Alexander Kuznetsov
Alexander Kuznetsov

Reputation: 3112

Deserialization with nested polymorphic objects via jakson Java

I have a container for nested objects like:

class A {
  private Type type;// can message or invite 
  private Notification notification;

}

and classes

abstract class Notification {}

class Message extends Notification {}

class Invite extends Notification {}

When I serialize List to JSON all works fine, but I can make deserialization with ObjectMapper because jackson doesn't know the the instance type of Notification, that are stored in type field. Question is it possible to deserialize with ObjectMapper?

Upvotes: 0

Views: 3481

Answers (1)

Mark Bakker
Mark Bakker

Reputation: 1348

I also struggled with this issue but there is a nice blog item here;

http://www.cowtowncoder.com/blog/archives/2010/03/entry_372.html

This should explain everything

Upvotes: 3

Related Questions