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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -