简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM