java - How do I discriminate types on the fly with Jackson -


i have json looks this:

[   {"type":"child_obj_1", "message": "blah"},   {"type":"child_obj_3", "apple": "red"},   {"type":"child_obj_2", "banana": "fire!"},   {"type":"doesnt_exist", "message": "blah"} ] 

these correspond types (the "doesnt_exist" type doesn't exist):

parentobj   -> childobj1   -> childobj2   -> childobj3 

i want able parse json list types. "doesnt_exist" type can fail silently. how do using jackson?

did try @jsontypeinfo annotation jackson ? check documentation more details.

sample usage:

 // include java class name ("com.myempl.implclass") json property "class"   @jsontypeinfo(use=id.class, include=as.property, property="class")    // include logical type name (defined in impl classes) wrapper; 2 annotations   @jsontypeinfo(use=id.name, include=as.wrapper_object)   @jsonsubtypes({com.myemp.impl1.class, com.myempl.impl2.class}) 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -