Filipe Correia
Filipe Correia

Reputation: 5687

Deserializing generic list of objects to the right type with Jackson

My json string has an array at the top level. E.g.:

[
  {...},
  {...}
]

And I'm using jackson to deserialize it like so:

val parser = mapper.getFactory.createParser(json)
val mylist = mapper.readValue(parser, classOf[List[Track]])

The trouble is that the values of the list are coming out as HashMap rather than Track objects, even though I'm specifying that this is a generic list of Tracks. On the console:

mylist.isInstanceOf[List[Track]]
> true
mylist.head.isInstanceOf[Track]
> false
mylist.head.isInstanceOf[HashMap]
> true

How can I do to make sure jackson returns Track objects instead of HashMap?

Upvotes: 1

Views: 973

Answers (0)

Related Questions