I have searched on json schema with java bindings with inheritance and all searches led me to the usage of \"allOf\".
Using allOf would potentially solve my problem
OK, well, I am the author of both:
So I can answer your question, and the basic answer is no.
Why? Because there is no such thing as schema inheritance currently defined.
When using allOf, you require that all schemas in allOf match; and if you are strict about what can exist in this or that JSON, you'll have added additionalProperties to false. As such, you cannot inherit.
The real solution is a mechanism I proposed for draft v5: the $merge and $patch keywords. These would allow to patch schemas with either of RFC 7386 or RFC 6902 (see here for more info) and indeed implement schema inheritance.
In short:
additionalProperties to false, and your basic JSON is an object, you won't be able to define additional object members;you have 3 options, I am using jsonschema2pojo : 1.0.0-alpha2
"extends": {
"$ref": "MyObject.json"
}
or
"extends": {
"type": "object",
"javaType": "com.mycompany.model.MyObject"
}
or
"extendsJavaClass" : "com.mycompany.model.MyObject"
"jsonschema2pojo" project contains notations for this purpose.
On the JSON schema, just include something like this;
"extendsJavaClass" : "com.somecompany.SomeBaseClass",
i.e.
{
"title": "....",
"description": "....",
"type": "object",
"extendsJavaClass" : "com.somecompany.SomeBaseClass",
"properties": {
"...": {
"items": {
"$ref": "#/definitions/...."
},
"type": "array"
}
.......
}
then the class generated by the project will have its "extends" clause as;
/**
* ...
* <p>
* ...
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
...
})
public class MyNewClass
extends SomeBaseClass
{
...
}
Also you can search for similar notations in here.
PS: Theese notations are not "standard JSON schema constructs". They are added for the sake of "just doing it" until a standard way of doing it is possible.
Hope it helps..