title: Is there a generic way of parsing Json in Java?
body: <p>I have tried with gson and Jackson parsers unfortunately I couldn't achieve what I wanted to.</p>
  
  <pre><code>{
     "rateName": "My Special Rate",
     "adjustments":    [
              {
           "adjustmentType": "LOAN_AMOUNT_GREATER_THAN_550K",
           "rate": 0.75
        },
              {
           "adjustmentType": "AMORTIZATION_TERM_LESS_THAN_30_YEARS",
           "rate": -0.2
        }
     ],
     "errorTypes": [],
     "premiumTaxs": [],
     "renewalPremiums": [],
     "totalInitialRate": 1.95,
     "optimumPricing": false,
     "miPricingVO": null,
     "rateCardId": "BALS_NR",
     "ratingInfoBaseRate": 1.4
  }
  </code></pre>
  
  <p>Above is the Json I want to parse. I want to create generic methods using which I can access a value by name easily. For example:</p>
  
  <ol>
  <li>getName(rateName) - Should return 'My  Special Rate'</li>
  <li>getNameFromArray(adjustmentType, adjustments) - Should return
  'LOAN_AMOUNT_GREATER_THAN_550K'</li>
  </ol>
  
  <p>Is there a way to do this? It should be generic so that this can be applied on any Json file.</p>
  
  <p>Additional info: I tried using Gson, but this parses the whole file and throws an error if it finds an array.</p>
  
  <pre><code>JsonReader j = new JsonReader(new FileReader("Path of Json"));
          j.beginObject();
          while (j.hasNext()) {
              String name = j.nextName();
  
              if (name.equals("rateName")) {
                  System.out.println(j.nextString());
              }
              System.out.println(name);
          }
  </code></pre>
  
  <p>I tried with jackson and encountered the same as Gson.</p>
  
  <pre><code>JsonFactory jfactory = new JsonFactory();
          JsonParser jParser = jfactory.createJsonParser("Path of Json");
          while (jParser.nextToken() != JsonToken.END_OBJECT) {
              System.out.println(jParser.getCurrentName());;
          }
  </code></pre>