user1713069
user1713069

Reputation: 51

JSON schema validation using java - ref

I am trying to validate my JSON using ( https://github.com/fge/json-schema-validator) schema validator.

  1. Do you recommend using jackson schema generation to generate JSON schemas or is there a better way ?

  2. I have an object called (Location) which has list of objects (BaseObject). I created a schema for location like this with a $ref to BaseObject. But validation fails with the error message - ["": domain: validation; keyword: properties; message: required property(ies) not found; missing: ["id","refName"]; required: ["id","refName"]]

Is there a mistake in the way I used the refs ?

Location.json - schema

{
   "type":"object",
   "properties":{
      "locationType":{
         "type":"string"
      },
      "mapsRefs":{
          "$ref": "file://localhost/c:/baseobject.json" 
         }
      }
   }
}

baseobject.json - schema

{
   "type":"object",
   "properties":{
      "refName":{
         "type":"string",
          "required":true
      },
      "id":{
         "type":"integer",
          "required":true
      },
      "refs":{
         "type":"array",
          "required":false,
         "items":{
            "type":"string"
         }
      }
   }

}

Upvotes: 4

Views: 3054

Answers (1)

Mihai Soloi
Mihai Soloi

Reputation: 383

To answer your first question, Jackson in my experience is the most easy to use and documented API to handle JSON on java.

For the second question you define the "id" and "refName" as required, you are either validating with the wrong schema, or not passing the required properties.

This does look a lot like this closed issue on github: https://github.com/fge/json-schema-validator/issues/22

Upvotes: 1

Related Questions