jsonschema2pojo
jsonschema2pojo copied to clipboard
Get Stackoverflow error if schema contains trees/cycle dependencies for children
Is it possible to have a field inside an array object pointing to an external array? Such a scheme fails with StackOverflowError.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"folders": {
"$ref": "#"
}
}
}
}
But this schema locally generates classes:
{
"type": "object",
"additionalProperties": false,
"properties": {
"folders": {
"type": "array",
"items": {
"$ref": "#/definitions/folder"
}
}
},
"definitions": {
"folder": {
"type": "object",
"properties": {
"folders": {
"type": "array",
"items": {
"$ref": "#/definitions/folder"
}
}
}
}
}
}
Could you write a gist and compile an example model?
I want to generate the following class:
@Generated("jsonschema2pojo")
public class MyFolder {
@JsonProperty("folders")
private List<Folder> folders = new ArrayList<Folder>();
}
@Generated("jsonschema2pojo")
public class Folder {
@JsonProperty("folders")
private List<Folder> folders = new ArrayList<Folder>();
}
The second scheme from the first message successfully does this. The first scheme throws an error. It seems to me that this is the same scheme, written in different ways
Yes, looks like there's a bug here in how the # reference is resolved. The first schema should just generate:
@Generated("jsonschema2pojo")
public class Folder {
@JsonProperty("folders")
private List<Folder> folders = new ArrayList<Folder>();
}
We have a variety of these self references in our tests, but something about this example is different. You're right it should work. We should add a test for this and fix.