Small Example of Jackson Scala Module?

Give this a shot:

val person = Person("fred", 25)
val mapper = new ObjectMapper()
mapper.registerModule(DefaultScalaModule)    

val out = new StringWriter
mapper.writeValue(out, person)
val json = out.toString()
println(json)

val person2 = mapper.readValue(json, classOf[Person])
println(person2)

EDIT

Just be sure to declare the Person class as top level as it will not work otherwise.

Leave a Comment