Reputation: 51
I am trying to validate my JSON using ( https://github.com/fge/json-schema-validator) schema validator.
Do you recommend using jackson schema generation to generate JSON schemas or is there a better way ?
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
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