Created
February 8, 2017 22:23
-
-
Save devshorts/f6d70a3fcf63709ca922bd3b0271a0f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class StringAnyVal @JsonCreator()(@(JsonValue@getter) value: String) extends AnyVal | |
case class AnyValHolder(anyVal: StringAnyVal) | |
class Jackson extends FlatSpec with Matchers { | |
val finatra = FinatraObjectMapper.create().objectMapper | |
val jackson = { | |
val o = new ObjectMapper with ScalaObjectMapper | |
o.registerModule(DefaultScalaModule) | |
o | |
} | |
val mapper = finatra | |
"Serializer" should "serialize anyval to raw" in { | |
mapper.writeValueAsString(StringAnyVal("test")) shouldEqual "\"test\"" | |
} | |
it should "deserialize anyval from raw" in { | |
mapper.readValue[StringAnyVal]("\"test\"") shouldEqual StringAnyVal("test") | |
} | |
it should "deserialize anyval holder" in { | |
val data = | |
"""{ | |
| "anyVal": "test" | |
|} | |
""".stripMargin | |
val x = mapper.readerFor(classOf[AnyValHolder]).readValue[AnyValHolder](data) | |
x shouldEqual AnyValHolder(StringAnyVal("test")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment