I'm trying to define a json schema where there are multiple properties that instances of the same object for a Java application endpoint.
A simple example of what I'm trying to do is this
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"last": {
"$ref": "#/$def/node"
},
"next": {
"$ref": "#/$def/node"
}
},
"$def": {
"node": {
"type": "object",
"properties": {
"item": "object"
}
}
}}
The issue is that when I pass this into jsonschema2pojo, it interprets this as last
and next
being distinct classes rather than instances of a common node
object.
-----------------------------------com.example.Last.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Last {
@SerializedName("item")
@Expose
public Object item;
}
-----------------------------------com.example.Next.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Next {
@SerializedName("item")
@Expose
public Object item;
}
-----------------------------------com.example.Node.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Node {
@SerializedName("last")
@Expose
public Last last;
@SerializedName("next")
@Expose
public Next next;
}
Is it possible to have multiple instances of a property in json-schema and would I express this? Or is this a limitation of the jsonschema2pojo tool/plugin? Or does json-schema require multiple instances be placed into an array?