title: Mapping JSON with nested object to GSON
body: <p>I have a JSON schema class that is auto generate using AVRO. I would like to create a GSON object using this JSON. I try to do so using this code </p>
  
  <pre><code>    @Test
      public void parseJson() {
  
          JSONParser jsonParser = new JSONParser();
          try {
              JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("/pathto/test.json"));
              ThinEvent thinEvent = new Gson().fromJson(jsonObject.toString(), ThinEvent.class);
          } catch (IOException e) {
              e.printStackTrace();
          } catch (ParseException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>but this results in the following error ... It looks like GSON is looking for a string but the json actually contains a nested object? The ThinEvent object has refService declared as a list.</p>
  
  <pre><code>com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 74 path $.references[0].refService
  </code></pre>
  
  <pre><code>private java.util.List&lt;com.lm.gde.eventing.avro.Reference&gt; references;
  </code></pre>
  
  <p>Here is my JSON, I have replaced some values with XXXX.</p>
  
  <pre><code>{
    "eventType": "policy.PolicyPremiumChangedEvent",
    "correlationId": "XXXX",
    "references": [
      {
        "ref": "XXX",
        "refType": "policy_id",
        "refService": {
          "com.lm.gde.eventing.avro.RefService": "policy_service"
        },
        "links": {
          "array": [
            {
              "refUri": ""
            }
          ]
        }
      },
      {
        "ref": "XXXXXX",
        "refType": "policy_number",
        "refService": {
          "com.lm.gde.eventing.avro.RefService": "policy_service"
        },
        "links": {
          "array": [
            {
              "refUri": "XXXXXX"
            }
          ]
        }
      },
      {
        "ref": "2019-09-28",
        "refType": "policy_tx_effective_date",
        "refService": {
          "com.lm.gde.eventing.avro.RefService": "policy_service"
        },
        "links": {
          "array": [
            {
              "refUri": "XXXXX"
            }
          ]
        }
      }
    ],
    "eventContext": null,
    "Timestamp": 1569574003295,
    "Version": "1"
  }
  </code></pre>