java - Jackson Custom Deserialization for Mapping Class Name String to Actual Class Definition -
i using jackson custom deserializers parse json file. in file there bunch of entries key "class" , value name of class (without full package name). deserializer knows bunch of predefined (hard) paths search class. custom deserializer should keyword "class" (while parsing json) , based on value (the class name string), search in predefined paths , instantiate object matching class name.
i have implemented jackson deserializers
interface , have overridden bunch of callbacks: findbeandeserializer
, findbeandeserializer
, findenumdeserializer
... not let me catch event when parser sees class:classname
key-value pair , act differently based on that.
any or pointers appreciated.
an example json
{ "class": "x", "fieldname1": { "class": "y", } ... }
i hope haven't spend time writing custom stuff. can use, out of box, annotation @jsontypeinfo
(see javadoc): makes jackson automatically read/write additional type information. , 1 possible inclusion mechanism as.property
, in case class name (or type name) added virtual property use. name of property can customized well.
Comments
Post a Comment