Skip to content

Instantly share code, notes, and snippets.

@ittaiz
Created October 9, 2013 16:12
Show Gist options
  • Save ittaiz/6903795 to your computer and use it in GitHub Desktop.
Save ittaiz/6903795 to your computer and use it in GitHub Desktop.
Test showing classes with an option[JsonNode] stopped serializing
import com.fasterxml.jackson.databind.{ObjectMapper, JsonNode}
import scala.Some
import org.specs2.mutable.SpecificationWithJUnit
import com.fasterxml.jackson.module.scala.DefaultScalaModule
class JsonNodeOptionDeserializerTest extends SpecificationWithJUnit {
"Option[JsonNode] " should {
"serialize its content when contained in an object" in {
val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
val json: String = """{"prop":"value"}"""
val tree: JsonNode = mapper.readTree( json)
val wrapperOfOptionOfJsonNode = WrapperOfOptionOfJsonNode(Some(tree))
val actualJson: String = mapper.writeValueAsString(wrapperOfOptionOfJsonNode)
actualJson mustEqual """{"jsonNode":{"prop":"value"}}"""
}
}
}
case class WrapperOfOptionOfJsonNode(jsonNode: Option[JsonNode])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment