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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -