Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson annotations broken in Scala from 1.9 to 2.1

Just upgraded Jackson from 1.9 to 2.1 and immediately noticed that @(JsonProperty@field) annotations are broken. Note the special @field for Scala case classes. Here's a sample:

case class Watcher(
  @(JsonProperty@field)("guid")
  @(RiakKey@field)
  val guid: String,

  @(JsonProperty@field)("socialNetwork")
  val socialNetwork: String, // instragram, twitter
)

When I go to pull a Watcher serialized as JSON from the database, Jackson goes to deserialize it and it throws the exception:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "guid" (class com.domain.SocialStreamService.models.Watcher), not marked as ignorable (0 known properties: ])

Now since this was working in 1.9, I am assuming something has changed. Anyone know the cause of the issue? Thanks!

like image 504
crockpotveggies Avatar asked Dec 07 '25 09:12

crockpotveggies


1 Answers

It was caused by a namespace issue and the fact that I was using Jerkson (which still pulled in 1.x as a dependency, thus not throwing compiler errors). To solve the issue, I had to go change the namespaces from com.codehaus to com.fasterxml.

In the meantime, there is a legacy introspector for those who need it: https://github.com/Laures/jackson-legacy-introspector

like image 102
crockpotveggies Avatar answered Dec 09 '25 23:12

crockpotveggies