title: RestTemplate JSON Deserialization
body: <p>so let's assume that we have two systems (system A and system B) that exchange information in JSON, however, the guys from System B do not want to be really cooperative and claim that everything with their payload is fine because it is "syntactically" correct JSON.</p>
  
  <p>Now let's assume that you have the following json structure</p>
  
  <pre><code>   {
      "INFO": {
          "Animal": {
              "Cat": {}
          }
      }
     }
  </code></pre>
  
  <p>This is really a valid JSON, but the thing is you can have one or more animals, so in the scenario of more animals the payload is: </p>
  
  <pre><code>   {
      "INFO": {
          "Animal": [{
              "Cat": {},
  "Dog" :{}
          }]
      }
     }
  </code></pre>
  
  <p>Only this time as you can see the Animal object is actually an array of objects...so System A uses RestTemplate to parse the response and has problems since the "syntactically" correct JSON differs in structure each time. Moreover, ERRORS might occur in the JSON as well - in case of errors the JSON looks like : <code>"ERRORS" : {[error1, error2, etc.]},</code> </p>
  
  <p>but in case of no errors it comes as </p>
  
  <pre><code>"ERRORS" : ""
  </code></pre>
  
  <p>So tell me please, am I wrong for wanting the payload to be consistent and get like always an array of objects, no matter one or many, and getting no errors node in case of no errors, or am I missing something?</p>
  
  <p>I'm using RestTemplate and</p>
  
  <p>when the payload comes with one Animal (my pojo expects 1 or many) -> it fails as it cannot parse a single object into array list.</p>
  
  <p>if I change it to expect only one Animal - it fails when more than one comes.</p>
  
  <p>More than that - the "ERRORS" : "" is treated as a String which again causes parses issues. </p>
  
  <p>So is there some "hack" way to make the Jackson deserializer in RestTemplate to handle this "syntactically" correct JSON, or the overall structure of the JSON should be clarified and consistent (my opinion)</p>
  
  <p>Thanks!</p>