How can we set default values for an array of objects in JSON schema definition?
The following shows the specific section of schema. The default data provided is not helping.
"children": {
"type": "array",
"items": {
"type": "object",
"properties": {
"fname": {
"type": "string"
},
"lname": {
"type": "string"
}
}
},
"default": [{
"fname": "x",
"lname": "ray"
}]
}
I am later converting this schema to java object using jsonschema2pojo maven plugin. So I am expecting the same default data to be available in the generated classes. The above mentioned approach works perfectly for sting, number etc.. but not for object array. Any help is highly appreciated.
the
defaultkeyword does not provide any validation assertion. It's merely an annotation. With that said, you can adddefaultto the schema property definition. There's no guarantee it will be used in the pojo generation. that's dependent on the implementation used.