KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a Java class MyPojo that I am interested in deserializing from JSON. I have configured a special MixIn class, MyPojoDeMixIn , to assist me with the deserialization. MyPojo has only int and String instance variables combined with proper getters and setters. MyPojoDeMixIn looks something like this: public abstract class MyPojoDeMixIn { MyPojoDeMixIn( @JsonProperty("JsonName1") int prop1, @JsonProperty("JsonName2") int prop2, @JsonProperty("JsonName3") String prop3) {} } In my test client I do the following, but of course it does not work at compile time because there is a JsonMappingException related to a type mismatch. ObjectMapper m = new ObjectMapper(); m.getDeserializationConfig().addMixInAnnotations(MyPojo.class,MyPojoDeMixIn.class); try { ArrayList<MyPojo> arrayOfPojo = m.readValue(response, MyPojo.class); } catch (Exception e) { System.out.println(e) } I am aware that I could alleviate this issue by creating a "Response" object that has only an ArrayList<MyPojo> in it, but then I would have to create these somewhat useless objects for every single type I want to return. I also looked online at JacksonInFiveMinutes but had a terrible time understanding the stuff about Map<A,B> and how it relates to my issue. If you cannot tell, I'm entirely new to Java and come from an Obj-C background. They specifically mention: In addition to binding to POJOs and "simple" types, there is one additional variant: that of binding to generic (typed) containers. This case requires special handling due to so-called Type Erasure (used by Java to implement generics in somewhat backwards compatible way), which prevents you from using something like Collecti
Tags (comma-separated)
Save Edits
Cancel