You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a JSON representation of a datamodel and want to use a JSON Schema to validate the contents. When using the JSON Schema generated by the jsonSchema module I run into trouble when I have a property which is an identify reference (@JsonIdentityReference(alwaysAsId = true)).
For example when we have three classes: ManagingObject (which manages everything), ReferencedObject (the object which is managed by ManagingObject) and ReferencingObject (an object which references to ReferencedObject and is also managed by ManagingObject):
When I then create a sample JSON using the following code:
// Create an example JSON.ObjectMapperobjectMapper = newObjectMapper();
ManagingObjectmo = newManagingObject();
// Create the ReferencedObject and add it to the ManagingObject collection.ReferencedObjectro = newReferencedObject();
ro.someOtherProperty = "Something";
mo.referencedObjects.add(ro);
// Create the ReferencingObject and set its referencedObject and also add a reference in the ManagingObject to it.ReferencingObjectrco = newReferencingObject();
rco.referencedObject = ro;
mo.referencingObject = rco;
// Create a JSON representation of the ManagingObject.System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mo));
Then the output is what I would expect (in the ReferencingObject it points directly to the id and doesn't include the full referencedObject):
When I look at the ReferencingObject definition of the schema I see a JSON Pointer to the ReferencedObject definition for the 'referencedObject' property, but in the example JSON the id is directly mapped (not a full JSON representation of the ReferencedObject). So the JSON produced is not valid according the JSON Schema on the same object model.
Am I doing something wrong or weird here? Or should the JSON Schema look a bit different for the properties which are marked with the annotation @JsonIdentityReference(alwaysAsId = true) ?
The text was updated successfully, but these errors were encountered:
Hi,
I am trying to create a JSON representation of a datamodel and want to use a JSON Schema to validate the contents. When using the JSON Schema generated by the jsonSchema module I run into trouble when I have a property which is an identify reference (
@JsonIdentityReference(alwaysAsId = true)
).For example when we have three classes: ManagingObject (which manages everything), ReferencedObject (the object which is managed by ManagingObject) and ReferencingObject (an object which references to ReferencedObject and is also managed by ManagingObject):
When I then create a sample JSON using the following code:
Then the output is what I would expect (in the ReferencingObject it points directly to the id and doesn't include the full referencedObject):
But when I then generate a JSON Schema using the following code:
Then the output is not what I would expect for the referencedObject in ReferencingObject (unless I misunderstand):
When I look at the ReferencingObject definition of the schema I see a JSON Pointer to the ReferencedObject definition for the 'referencedObject' property, but in the example JSON the id is directly mapped (not a full JSON representation of the ReferencedObject). So the JSON produced is not valid according the JSON Schema on the same object model.
Am I doing something wrong or weird here? Or should the JSON Schema look a bit different for the properties which are marked with the annotation
@JsonIdentityReference(alwaysAsId = true)
?The text was updated successfully, but these errors were encountered: