java - jackson deserialization into pojos -


I am trying to deserialize the JSON object which is coming from an application that I can not control. {"Name": "mm9", "id": 32, "chromosome": [{"chromosome": {"name": "MT"}}]}}

my Pojos,

  class assembly {private string name; Private Ent ID; Private Arrestist & lt; Chromosomes> Chromosomes; // Miller & amp; Amp; Setters} class chromosom {Private string name; // getter / setters}   

but this additional field is not working due to "assembly"; "Chromosome", such as with a JSON:

  {"name": "mm9", "id": 32, "chromosom": [{"name": "MT"}] }}   

Is this just a way to get any configuration or modify it without getting more complex POJOS working?

The problem is first in the JSON snippet, chromosom is a dictionary , One of which is the entry ( chromosome ) corresponding to your chromosome objects.

There will be a more accurate direct mapping for the Java class

  class assembly ... ... private map & lt; String, chromosome & gt; Chromosomes; }   

Since you mention that you can not control the format of the source JSON, you can try using Jackson's support instead of the object mapper for mapping directly. If you are not happy with changing your POO in this way.

By the way, instead of concrete type, their interface type ( list ) should be the best in terms of archive ArrayList ). It is very unlikely that the code referencing this class really cares or it is important to know that it is using a ArrayList , only the list interface Instead of referencing it makes it very easy to swap other implementations if needed. (As a general principle).

Comments