java - Universal Json Deserializer for enum who implements interface -
i have enum:
@jsonformat (shape = shape.object) public enum esample implements identifiable { sample1(1l, "title 1"), sample2(2l, "title 2"); private final long id; private final string title; private esample(long id, string title) { this.id = id; this.title = title; } @override public long getid() { return id; } }
class uses it:
public class testclass { @jsondeserialize (using = esampledeserializer.class) public esample sample; }
and esampledeserializer:
public class edirectiondeserializer extends jsondeserializer<esample> { @override public esample deserialize(jsonparser jp, deserializationcontext ctxt) throws ioexception, jsonprocessingexception { return //deserialize id } }
working example of use:
string json= "{\"sample\":{\"id\":1}}"; testclass testobj= new objectmapper().readvalue(json, testclass.class);
can make universal json deserializer enum implements identifiable?
Comments
Post a Comment