title: Generate Java class from JSON?
body: <p>In a Java Maven project, how do you generate java source files from JSON? For example we have</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;firstName&quot;: &quot;John&quot;,  
    &quot;lastName&quot;: &quot;Smith&quot;,  
    &quot;address&quot;: {  
      &quot;streetAddress&quot;: &quot;21 2nd Street&quot;,  
       &quot;city&quot;: &quot;New York&quot;
    }
  }
  </code></pre>
  <p>When we run <code>mvn generate-sources</code> we want it to generate something like this:</p>
  <pre class="lang-java prettyprint-override"><code>class Address  {
      JSONObject mInternalJSONObject;
       
      Address (JSONObject json){
          mInternalJSONObject = json;
      }
       
      String  getStreetAddress () {
          return mInternalJSONObject.getString(&quot;streetAddress&quot;);
      }
      
      String  getCity (){
          return mInternalJSONObject.getString(&quot;city&quot;);
      }
  }
  
  class Person {        
      JSONObject mInternalJSONObject;
      
      Person (JSONObject json){
          mInternalJSONObject = json;
      }
      
      String  getFirstName () {
          return mInternalJSONObject.getString(&quot;firstName&quot;);
      }
      
      String  getLastName (){
          return mInternalJSONObject.getString(&quot;lastName&quot;);
      }
      
      Address getAddress (){
          return Address(mInternalJSONObject.getString(&quot;address&quot;));
      }
  }
  </code></pre>
  <p>As a Java developer, what lines of XML do I need to write in my <code>pom.xml</code> in order to make this happen?</p>