jackson-module-jsonSchema
jackson-module-jsonSchema copied to clipboard
Multiple occurrences of the same object results in $ref instead of inlining
Sorry in advance if this is a duplicate of an existing issue or by design. I am using v2.7.3, but for example, with sample code like so:
public User createUser() {
User me = new User();
me.age = 30;
me.firstName = new Name("foo");
me.lastName = new Name("bar");
}
class User {
public int age;
public Name firstName;
public Name lastName;
}
class Name {
private final String name;
Name(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
I get the following output.
{
"type" : "object",
"id" : "urn:jsonschema:com:tsz662:sample:User",
"properties" : {
"age" : {
"type" : "integer"
},
"firstName" : {
"type" : "object",
"id" : "urn:jsonschema:com:tsz662:sample:Name",
"properties" : {
"name" : {
"type" : "string"
}
}
},
"lastName" : {
"type" : "object",
"$ref" : "urn:jsonschema:com:tsz662:sample:Name"
}
}
}
The lastName property is $refed, not inlined, possibly because firstName has already been inlined.
Is this by design or should I override VisitorContext?
Never mind. I will just override VisitorContext.getSeenSchemaUri() to return null.
I have to add that the above works as long as the model objects do not self-reference themselves.