Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think, you should separate deserialization logic from the way how to retrieve names at the end. For deserialization use as simle method as you can. For example, you can create POJO classes which describe your JSON. See below example. POJO classes:</p> <pre><code>class EntitiesOwner { private String name; private List&lt;Entity&gt; entities; @JsonAnySetter public void setProperties(String name, List&lt;Entity&gt; entities) { this.name = name; this.entities = entities; } public String getName() { return name; } public List&lt;Entity&gt; getEntities() { return entities; } @Override public String toString() { return "EntitiesOwner [name=" + name + ", entities=" + entities + "]"; } } class Entity { private int id; private String afk; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getAfk() { return afk; } public void setAfk(String afk) { this.afk = afk; } public void setCat(String cat) { this.afk = cat; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Entity [id=" + id + ", afk=" + afk + ", name=" + name + "]"; } } </code></pre> <p>Now you can easily deserialize it in this way:</p> <pre><code>ObjectMapper mapper = new ObjectMapper(); EntitiesOwner[] owners = mapper.readValue(json, EntitiesOwner[].class); System.out.println(Arrays.toString(owners)); </code></pre> <p>Above program prints:</p> <pre><code>[EntitiesOwner [name=Opleidingen, entities=[Entity [id=0, afk=BTZW, name=Bijz. trajecten zorg en welzijn], Entity [id=14, afk=Bwk, name=Bouwkunde], Entity [id=15, afk=EltMe, name=Electrotechniek / mechatronica], Entity [id=16, afk=Extern, name=Extern], Entity [id=17, afk=Zorg, name=Gezondheidszorg], Entity [id=18, afk=Hand, name=Handel], Entity [id=19, afk=Hor, name=Horeca], Entity [id=20, afk=ICT, name=Ict], Entity [id=21, afk=MZ, name=Maatschappelijke zorg], Entity [id=22, afk=OAPW, name=Onderwijs assistent / pedagogisch werk], Entity [id=23, afk=TAB, name=Tab / brug], Entity [id=24, afk=WtbMt, name=Werktuigbouw / maritieme techniek], Entity [id=25, afk=TAB, name=Zakelijke dienstverlening]]], EntitiesOwner [name=Klassen, entities=[Entity [id=1, afk=BTZW, name=V2ZWA], Entity [id=2, afk=Bwk, name=V2ZWB], Entity [id=3, afk=BTZW, name=V2ZWB], Entity [id=3, afk=BTZW, name=V3B2A], Entity [id=4, afk=BTZW, name=V3B2B], Entity [id=5, afk=BTZW, name=V3B2C], Entity [id=6, afk=BTZW, name=V3B2D], Entity [id=7, afk=BTZW, name=V3B2E], Entity [id=8, afk=BTZW, name=V3B3A], Entity [id=9, afk=BTZW, name=V3B3B], Entity [id=10, afk=BTZW, name=V3B3C], Entity [id=11, afk=BTZW, name=VWA], Entity [id=12, afk=BTZW, name=VWB], Entity [id=13, afk=BTZW, name=VWC]]]] </code></pre> <p>For resolving entities I propose to create new class which can help you with this. For example:</p> <pre><code>class EntityResolver { private Map&lt;Integer, Entity&gt; entities; public EntityResolver(EntitiesOwner[] owners) { entities = new HashMap&lt;Integer, Entity&gt;(owners.length); for (EntitiesOwner owner : owners) { for (Entity entity : owner.getEntities()) { entities.put(entity.getId(), entity); } } } public Entity getById(int id) { return entities.get(id); } } </code></pre> <p>Simple usage:</p> <pre><code>EntityResolver resolver = new EntityResolver(owners); System.out.println(resolver.getById(0).getName()); System.out.println(resolver.getById(13).getName()); </code></pre> <p>Above program prints:</p> <pre><code>Bijz. trajecten zorg en welzijn VWC </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload