title: How to convert dynamic Json to specific format of POJO class using Java
body: <p><strong>Input Json file looks like below code:</strong></p>
  
  <pre><code> {
        "Payload": {
          "any0": {
            "pricingResponse": {
              "priceDetails": {
                "priceDetails": {
                  "seqId": "8015B000000Umo1QAC-",
                  "companyCode": "EPA",
                  "priceType": "Fuel Price",
                  "priceRequestSource": ""
                },
                "priceLineItems": {
                  "lineItem": [
                    {
                      "lineItemInfo": {
                        "seqId": "8015B000000Umo1QAC-28052018105047-022596",
                        "orderId": "00000266",
                        "lineItemId": "44",
                        "itemId": "70051",
                        "quantity": "100.00",
                        "unitPrice": "2.03200",
                        "unitPriceLCY": "2.03200"
                                     }
                      }
                              ]
                      }
                  }
               }
             }
           }
        }
  </code></pre>
  
  <p><strong>Expected output(java class)</strong></p>
  
  <pre><code> public class Payload 
     {
        public Any0 any0;
     }
  
      /* Stub Class for Any0 */
     public class Any0 
     {
          public PricingResponse pricingResponse;
     }
  
      /* Stub Class for PricingResponse */
      public class PricingResponse 
      {
          public PriceDetails priceDetails;
      }
  
      /* Stub Class for PriceDetails */
      public class PriceDetails 
      {
          public String seqId;
          public String priceRequestSource;
          public String companyCode;
          public String priceType;
          public String deliveryType;
          public String currencyCode;
          public String priceDate;
          public String applyOrderQuantity;
          public String totalOrderQuantity;
          public String customerId;
          public String shipToId;
          public String supplyLocationId;
          public String transporterId;
          public String onRun;
          public String orderId;
          public PriceDetails priceDetails;
          public PriceLineItems priceLineItems;
          public Error Error;
      }
  
      /* Stub Class for PriceLineItems */
      public class PriceLineItems 
      {
          public String orderId;
          public List&lt;LineItem&gt; lineItem;
      }
  
      /* Stub Class for LineItem */
      public class LineItem 
      {
          public LineItemInfo lineItemInfo;
          public AccountingDetails accountingDetails;
          public Error Error;
      }
  </code></pre>
  
  <p>I tried to convert it using Jackson Library it's working and creating as the separate POJO classes but I want to create nested class.This is my sample code</p>
  
  <pre><code>  public void convert2JSON(URL inputJson, File outputPojoDirectory, String packageName, String className) throws IOException
     {  
            JCodeModel codeModel = new JCodeModel();  
            URL source = inputJson;  
            GenerationConfig config = new DefaultGenerationConfig()
       {  
            @Override  
            public boolean isGenerateBuilders() 
            { // set config option by overriding method  
              return true;  
            }  
            public SourceType getSourceType()
            {  
              return SourceType.JSON;  
            }  
  
       };  
            SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new Jackson2Annotator(config), new SchemaStore()), new SchemaGenerator());  
            mapper.generate(codeModel, className, packageName, source);  
            codeModel.build(outputPojoDirectory);  
     }
  </code></pre>
  
  <p>This is the output I am getting 
  <a href="https://i.stack.imgur.com/scZOO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/scZOO.png" alt="enter image description here"></a></p>
  
  <p>Is there a possible way to convert dynamic nested Json class file into Java class? Any help would be appreciated. </p>