title: How to create class for dynamic JSON structure in Spring Boot Java
body: <p>I have following JSON structure as input which can be nested and without nested. I want to fetch the JSON as input and process in Spring Boot application. How to create a class which dynamic key values in the JSON. It can be any key-value pairs in the JSON input. Below is the sample one.</p>
  <p>Without Nested:</p>
  <pre><code>{
      &quot;mappings&quot;: {
          &quot;properties&quot;: {
              &quot;firstname&quot;: {
                  &quot;type&quot;: &quot;string&quot;
              },
              &quot;lastname&quot;: {
                  &quot;type&quot;: &quot;string&quot;
              },
              &quot;salary&quot;: {
                  &quot;type&quot;: &quot;integer&quot;
              },
              &quot;date_of_birth&quot;: {
                  &quot;type&quot;: &quot;date&quot;
              }
          }
      }
  }
  </code></pre>
  <p>With Nested:</p>
  <pre><code>{
      &quot;mappings&quot;: {
          &quot;properties&quot;: {
              &quot;firstname&quot;: {
                  &quot;type&quot;: &quot;string&quot;
              },
              &quot;lastname&quot;: {
                  &quot;type&quot;: &quot;string&quot;
              },
              &quot;annual_salary&quot;: {
                  &quot;type&quot;: &quot;integer&quot;
              },
              &quot;date_of_birth&quot;: {
                  &quot;type&quot;: &quot;date&quot;
              },
              &quot;comments&quot;: {
                  &quot;type&quot;: &quot;nested&quot;,
                  &quot;properties&quot;: {
                      &quot;name&quot;: {
                          &quot;type&quot;: &quot;string&quot;
                      },
                      &quot;comment&quot;: {
                          &quot;type&quot;: &quot;string&quot;
                      },
                      &quot;age&quot;: {
                          &quot;type&quot;: &quot;short&quot;
                      },
                      &quot;stars&quot;: {
                          &quot;type&quot;: &quot;short&quot;
                      },
                      &quot;date&quot;: {
                          &quot;type&quot;: &quot;date&quot;
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  <p>I don't know how to create a class to support both with and without nested in single class. I have tried the following. It doesn't help.</p>
  <pre><code>public class Schema {
      Mapping mappings;
  
      public Mapping getMappings() {
          return mappings;
      }
  
      public void setMappings(Mapping mappings) {
          this.mappings = mappings;
      }
  
      public static class Mapping {
          Property properties;
  
          public Property getProperties() {
              return properties;
          }
  
          public void setProperties(Property properties) {
              this.properties = properties;
          }
      }
  
      public static class Property {
          Map&lt;String, Map&lt;String, Object&gt;&gt; field = new HashMap&lt;&gt;();
  
          public Map&lt;String, Map&lt;String, Object&gt;&gt; getField() {
              return field;
          }
  
          public void setField(Map&lt;String, Map&lt;String, Object&gt;&gt; field) {
              this.field = field;
          }
      }
  }
  </code></pre>