title: Schema validation for Json array of objects using Java
body: <p>I am looking for JSON Schema validation in java code for an array of data.</p>
  
  <p>My JSON Schema is </p>
  
  <pre><code>{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
      "acc": {
        "type": "array",
        "items": [
          {
            "type": "object",
            "properties": {
              "AccId": {
                "type": "integer"
              },
              "accName": {
                "type": "string"
              },
              "accSysName": {
                "type": "string"
              },
              "accLName": {
                "type": "string"
              }
             },
            "required": [
              "AccId",
              "accName",
              "accSysName",
              "accLName"
            ]
          }
        ]
      }
    },
    "required": [
      "acc"
    ]
  }
  </code></pre>
  
  <p>while my JSON response for 1 record is</p>
  
  <pre><code>{
    "acc": [
      {
        "AccId": 123,
        "accName": "test",
        "accSysName": "ABC",
        "accLName": "test"
      }
    ]
  }
  </code></pre>
  
  <p>My code from <a href="http://wilddiary.com/validate-json-against-schema-in-java/" rel="nofollow noreferrer">http://wilddiary.com/validate-json-against-schema-in-java/</a> works fine in the above case but in the below case it doesnt go for the check of the second record , that is when JSON response has multiple objects.</p>
  
  <p>JSON response for multiple records:</p>
  
  <pre><code>{
    "acc": [
      {
        "AccId": 123,
        "accName": "test",
        "accSysName": "Abc",
        "accLName": "test"
      },
      {
        "pqr": 456,
        "qwe": "test2",
        "accSysName": "ghu",
        "accLName": "test3"
      }
    ]
  }
  </code></pre>
  
  <p>I tried with additionalProperties / additionalItems: false as well, yet it didn't work for either of them which I had checked for few old posts in Stack Overflow as well but didn't get the desired result.</p>
  
  <p>Is there any other way in which it can work?</p>