Created
June 5, 2015 07:27
-
-
Save noam-almog/153dc998d83379dee9c9 to your computer and use it in GitHub Desktop.
java and scala enums using hoopoe json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wixpress.mobile.ecom.cart | |
import com.fasterxml.jackson.core.`type`.TypeReference | |
import com.fasterxml.jackson.module.scala.JsonScalaEnumeration | |
import org.specs2.mutable.SpecificationWithJUnit | |
import org.specs2.specification.Scope | |
import com.wixpress.hoopoe.json._ | |
import com.wixpress.hoopoe.json.JsonMapper.Implicits.global | |
class JacksonEnumTest extends SpecificationWithJUnit { | |
trait ctx extends Scope { | |
val scalaEnum = WeekdayHolder(Weekday.Wed) | |
val javaEnum = JavaWeekdayHolder(JavaWeekday.Wed) | |
} | |
"JacksonEnum" should { | |
"marshall and unmarshall of scala enum" in new ctx { | |
scalaEnum.asJsonStr.as[WeekdayHolder] mustEqual scalaEnum | |
} | |
"marshall and unmarshall of java enum" in new ctx { | |
javaEnum.asJsonStr.as[JavaWeekdayHolder] mustEqual javaEnum | |
} | |
"unmarshall java to scala" in new ctx { | |
javaEnum.asJsonStr.as[WeekdayHolder] mustEqual scalaEnum | |
} | |
"unmarshall scala to java" in new ctx { | |
scalaEnum.asJsonStr.as[JavaWeekdayHolder] mustEqual javaEnum | |
} | |
} | |
} | |
object Weekday extends Enumeration { | |
type Weekday = Value | |
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value | |
} | |
class WeekdayType extends TypeReference[Weekday.type] | |
case class WeekdayHolder(@JsonScalaEnumeration(classOf[WeekdayType]) weekday: Weekday.Weekday) | |
case class JavaWeekdayHolder(weekday: JavaWeekday) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment