title: Mapping dynamic json object from parameter to POJO
body: <p>I am using resttemplate to get a json response body, which looks like this :</p>
  <pre><code>{
  &quot;entities&quot;: {
      &quot;Q11649&quot;: {
          &quot;type&quot;: &quot;item&quot;,
          &quot;id&quot;: &quot;Q11649&quot;,
          &quot;sitelinks&quot;: {
              &quot;enwiki&quot;: {
                  &quot;site&quot;: &quot;enwiki&quot;,
                  &quot;title&quot;: &quot;Nirvana (Band)&quot;,
                  &quot;badges&quot;: []
              },
                ..
  </code></pre>
  <p>The object &quot;Q11649&quot; is based on a url parameter called ids, for example :
  <a href="https://www.wikidata.org/w/api.php?action=wbgetentities&amp;format=json&amp;props=sitelinks&amp;ids=Q11649" rel="nofollow noreferrer">https://www.wikidata.org/w/api.php?action=wbgetentities&amp;format=json&amp;props=sitelinks&amp;ids=Q11649</a></p>
  <p>this part at the end <b>ids=Q11649</b></p>
  <p>I only want the title value from under enwiki key, however the ids is dynamic so I can't create a POJO to map it to that id.</p>
  <p>How can create a dynamic resttemplate method to extract only the title from this json structure?</p>
  <p>I have a Wikidata class that looks like this :</p>
  <pre><code>@JsonIgnoreProperties(ignoreUnknown = true)
  public class Wikidata {
  
    @JsonProperty(&quot;entities&quot;)
    private Entity entity;
  
    public Wikidata () {
  
    }
  
    public Wikidata(Entity entity) {
      this.entity = entity;
    }
  
    public Entity getEntities() {
      return entity;
    }
  
    public void setEntities(Entity entity) {
      this.entity = entity;
    }
  
  }
  </code></pre>
  <p>After reading a few articles, I realise that a map is probably the best way to go, this is how my entity class looks like :</p>
  <pre><code>@JsonIgnoreProperties(ignoreUnknown = true)
  public class Entity {
  
    @JsonProperty()
    private Map&lt;Object, Object&gt; data;
    
    public Entity () {
      data = new HashMap&lt;&gt;();
    }
    public Map&lt;Object, Object&gt; getData(){
      return data;
    }
    
    @JsonAnySetter
    public void add(String property, String value){
      data.put(property, value);
    }
  }
  </code></pre>
  <p>My Sitelinks class :</p>
  <pre><code> @JsonIgnoreProperties(ignoreUnknown = true)
  public class Sitelinks {
  
    private Enwiki enwiki;
  
    public Sitelinks () {
  
    }
  
    public Sitelinks(Enwiki enwiki) {
      this.enwiki = enwiki;
    }
  
    public Enwiki getEnwiki() {
      return enwiki;
    }
  
    public void setEnwiki(Enwiki enwiki) {
      this.enwiki = enwiki;
    }
  
  }
  </code></pre>
  <p>And my Enwiki class :</p>
  <pre><code>   @JsonIgnoreProperties(ignoreUnknown = true)
      public class Enwiki {
      
        private String title;
      
        public Enwiki () {
      
        }
      
        public Enwiki(String title) {
          this.title = title;
        }
      
        public String getTitle() {
          return title;
        }
      
        public void setTitle(String title) {
          this.title = title;
        }
  }
  </code></pre>
  <p>How can I use this map to link between the dynamic id and my sitelinks class so that I can get the title value?</p>