title: How to map a dynamic json property name with jackson for spring rest template request
body: <p>I am trying to send request with rest template. normally it works but I need a dynamic jackson object for this type of data</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;id&quot;: 1,
    &quot;name&quot;: &quot;Name Of role&quot;,
    &quot;permissions&quot;: {
      &quot;global&quot;: [],
      &quot;station&quot;: {
        &quot;ID&quot;: [
          &quot;String&quot;,
          &quot;String&quot;,
          &quot;String&quot;,
          &quot;String&quot;
        ]
      }
    }
  }
  </code></pre>
  <p>in this case I am trying to change property &quot;ID&quot; dynamically but I had bad luck with anygetter of jackson.
  Normally I am creating my object with <a href="https://www.jsonschema2pojo.org/" rel="nofollow noreferrer">jsonchema2pojo</a>. and my objects are kinda big actually. I am doing something wrong but I can't see where for this problem. Or I am searching for wrong context on google.</p>
  <p>additioanly here is the code generated for my request object:</p>
  <pre class="lang-java prettyprint-override"><code>
  package com.example;
  
  import java.util.HashMap;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
  &quot;id&quot;,
  &quot;name&quot;,
  &quot;permissions&quot;
  })
  @Generated(&quot;jsonschema2pojo&quot;)
  public class CreateRoleRequestDto {
  
  @JsonProperty(&quot;id&quot;)
  private Integer id;
  @JsonProperty(&quot;name&quot;)
  private String name;
  @JsonProperty(&quot;permissions&quot;)
  private Permissions permissions;
  @JsonIgnore
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  @JsonProperty(&quot;id&quot;)
  public Integer getId() {
  return id;
  }
  
  @JsonProperty(&quot;id&quot;)
  public void setId(Integer id) {
  this.id = id;
  }
  
  @JsonProperty(&quot;name&quot;)
  public String getName() {
  return name;
  }
  
  @JsonProperty(&quot;name&quot;)
  public void setName(String name) {
  this.name = name;
  }
  
  @JsonProperty(&quot;permissions&quot;)
  public Permissions getPermissions() {
  return permissions;
  }
  
  @JsonProperty(&quot;permissions&quot;)
  public void setPermissions(Permissions permissions) {
  this.permissions = permissions;
  }
  
  @JsonAnyGetter
  public Map&lt;String, Object&gt; getAdditionalProperties() {
  return this.additionalProperties;
  }
  
  @JsonAnySetter
  public void setAdditionalProperty(String name, Object value) {
  this.additionalProperties.put(name, value);
  }
  
  @Override
  public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append(CreateRoleRequestDto.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
  sb.append(&quot;id&quot;);
  sb.append('=');
  sb.append(((this.id == null)?&quot;&lt;null&gt;&quot;:this.id));
  sb.append(',');
  sb.append(&quot;name&quot;);
  sb.append('=');
  sb.append(((this.name == null)?&quot;&lt;null&gt;&quot;:this.name));
  sb.append(',');
  sb.append(&quot;permissions&quot;);
  sb.append('=');
  sb.append(((this.permissions == null)?&quot;&lt;null&gt;&quot;:this.permissions));
  sb.append(',');
  sb.append(&quot;additionalProperties&quot;);
  sb.append('=');
  sb.append(((this.additionalProperties == null)?&quot;&lt;null&gt;&quot;:this.additionalProperties));
  sb.append(',');
  if (sb.charAt((sb.length()- 1)) == ',') {
  sb.setCharAt((sb.length()- 1), ']');
  } else {
  sb.append(']');
  }
  return sb.toString();
  }
  
  @Override
  public int hashCode() {
  int result = 1;
  result = ((result* 31)+((this.name == null)? 0 :this.name.hashCode()));
  result = ((result* 31)+((this.id == null)? 0 :this.id.hashCode()));
  result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
  result = ((result* 31)+((this.permissions == null)? 0 :this.permissions.hashCode()));
  return result;
  }
  
  @Override
  public boolean equals(Object other) {
  if (other == this) {
  return true;
  }
  if ((other instanceof CreateRoleRequestDto) == false) {
  return false;
  }
  CreateRoleRequestDto rhs = ((CreateRoleRequestDto) other);
  return (((((this.name == rhs.name)||((this.name!= null)&amp;&amp;this.name.equals(rhs.name)))&amp;&amp;((this.id == rhs.id)||((this.id!= null)&amp;&amp;this.id.equals(rhs.id))))&amp;&amp;((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&amp;&amp;this.additionalProperties.equals(rhs.additionalProperties))))&amp;&amp;((this.permissions == rhs.permissions)||((this.permissions!= null)&amp;&amp;this.permissions.equals(rhs.permissions))));
  }
  
  }
  
  package com.example;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
  &quot;global&quot;,
  &quot;station&quot;
  })
  @Generated(&quot;jsonschema2pojo&quot;)
  public class Permissions {
  
  @JsonProperty(&quot;global&quot;)
  private List&lt;Object&gt; global = null;
  @JsonProperty(&quot;station&quot;)
  private Station station;
  @JsonIgnore
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  @JsonProperty(&quot;global&quot;)
  public List&lt;Object&gt; getGlobal() {
  return global;
  }
  
  @JsonProperty(&quot;global&quot;)
  public void setGlobal(List&lt;Object&gt; global) {
  this.global = global;
  }
  
  @JsonProperty(&quot;station&quot;)
  public Station getStation() {
  return station;
  }
  
  @JsonProperty(&quot;station&quot;)
  public void setStation(Station station) {
  this.station = station;
  }
  
  @JsonAnyGetter
  public Map&lt;String, Object&gt; getAdditionalProperties() {
  return this.additionalProperties;
  }
  
  @JsonAnySetter
  public void setAdditionalProperty(String name, Object value) {
  this.additionalProperties.put(name, value);
  }
  
  @Override
  public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append(Permissions.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
  sb.append(&quot;global&quot;);
  sb.append('=');
  sb.append(((this.global == null)?&quot;&lt;null&gt;&quot;:this.global));
  sb.append(',');
  sb.append(&quot;station&quot;);
  sb.append('=');
  sb.append(((this.station == null)?&quot;&lt;null&gt;&quot;:this.station));
  sb.append(',');
  sb.append(&quot;additionalProperties&quot;);
  sb.append('=');
  sb.append(((this.additionalProperties == null)?&quot;&lt;null&gt;&quot;:this.additionalProperties));
  sb.append(',');
  if (sb.charAt((sb.length()- 1)) == ',') {
  sb.setCharAt((sb.length()- 1), ']');
  } else {
  sb.append(']');
  }
  return sb.toString();
  }
  
  @Override
  public int hashCode() {
  int result = 1;
  result = ((result* 31)+((this.station == null)? 0 :this.station.hashCode()));
  result = ((result* 31)+((this.global == null)? 0 :this.global.hashCode()));
  result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
  return result;
  }
  
  @Override
  public boolean equals(Object other) {
  if (other == this) {
  return true;
  }
  if ((other instanceof Permissions) == false) {
  return false;
  }
  Permissions rhs = ((Permissions) other);
  return ((((this.station == rhs.station)||((this.station!= null)&amp;&amp;this.station.equals(rhs.station)))&amp;&amp;((this.global == rhs.global)||((this.global!= null)&amp;&amp;this.global.equals(rhs.global))))&amp;&amp;((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&amp;&amp;this.additionalProperties.equals(rhs.additionalProperties))));
  }
  
  }
  
  package com.example;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
  &quot;ID&quot;
  })
  @Generated(&quot;jsonschema2pojo&quot;)
  public class Station {
  
  @JsonProperty(&quot;ID&quot;)
  private List&lt;String&gt; id = null;
  @JsonIgnore
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  @JsonProperty(&quot;ID&quot;)
  public List&lt;String&gt; getId() {
  return id;
  }
  
  @JsonProperty(&quot;ID&quot;)
  public void setId(List&lt;String&gt; id) {
  this.id = id;
  }
  
  @JsonAnyGetter
  public Map&lt;String, Object&gt; getAdditionalProperties() {
  return this.additionalProperties;
  }
  
  @JsonAnySetter
  public void setAdditionalProperty(String name, Object value) {
  this.additionalProperties.put(name, value);
  }
  
  @Override
  public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append(Station.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
  sb.append(&quot;id&quot;);
  sb.append('=');
  sb.append(((this.id == null)?&quot;&lt;null&gt;&quot;:this.id));
  sb.append(',');
  sb.append(&quot;additionalProperties&quot;);
  sb.append('=');
  sb.append(((this.additionalProperties == null)?&quot;&lt;null&gt;&quot;:this.additionalProperties));
  sb.append(',');
  if (sb.charAt((sb.length()- 1)) == ',') {
  sb.setCharAt((sb.length()- 1), ']');
  } else {
  sb.append(']');
  }
  return sb.toString();
  }
  
  @Override
  public int hashCode() {
  int result = 1;
  result = ((result* 31)+((this.id == null)? 0 :this.id.hashCode()));
  result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
  return result;
  }
  
  @Override
  public boolean equals(Object other) {
  if (other == this) {
  return true;
  }
  if ((other instanceof Station) == false) {
  return false;
  }
  Station rhs = ((Station) other);
  return (((this.id == rhs.id)||((this.id!= null)&amp;&amp;this.id.equals(rhs.id)))&amp;&amp;((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&amp;&amp;this.additionalProperties.equals(rhs.additionalProperties))));
  }
  
  }
  
  </code></pre>