json - Custom Deserialization using Jackson in Java -
i trying implement university project try fetch values 2 json fields , map 1 pojo class.
sample json:
"event":[{"d17-32":0,"s10":"d"}]
pojo class
public class event { @jsondeserialize(using = signalcustomdeserializer.class) @jsontypeinfo(use = jsontypeinfo.id.none) @jsonproperty("s10") private signal s10; @jsonproperty("d17-32") private string d17_32; //getter , setter implementation }
class need serialize fields
public class signal{ private string value; private string detectorid; private int detectorvalue; //this value has fetched json //getter , setter implementation }
custom deserializer class
public class signalcustomdeserializer extends jsondeserializer { @override public signal deserialize(jsonparser jsonparser, deserializationcontext deserializationcontext) throws ioexception, jsonprocessingexception { string signalid = jsonparser.getcurrentname(); string signalval = jsonparser.getvalueasstring(); string detectorval = jsonparser.getvalueasstring("d01-16"); signal signal = new signal(); signal.setvalue(signalval); signal.setdetectorid(getdetectorid(signalid)); return signal; } }
i able signalid , signalvalue unable value other field. unsure if available in jsonobject when custom deserialization class called.
Comments
Post a Comment