Issue generating nested interface object
Closed this issue · 1 comments
Hello team,
I wanted to reach out highlighting an issue generating a nested interface object please.
Please allow me to show a simple concrete example.
I have a class Farm which contains one (it is an example) Animal (interface).
The concrete Animal would be a Cow, Sheep, whatever.
public class Farm {
private String name;
private int capacity;
private Animal animal;
//getters and setters
public interface Animal {
}
public class Cow implements Animal {
private String name;
private int age;
//getters and setters
public class Sheep implements Animal {
private String name;
private String color;
//getters and setters
I am using this code in order to generate the schema:
public class GenerateSchemaTest {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchema schema = schemaGen.generateSchema(Farm.class);
String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
System.out.println(schemaString);
}
}
And I was hoping to get something like this: (Expected result)
{
"type" : "object",
"id" : "urn:jsonschema:com:schema:Farm",
"properties" : {
"name" : {
"type" : "string"
},
"capacity" : {
"type" : "integer"
},
"animal" : {
"type" : "object",
"id" : "urn:jsonschema:com:schema:Cow",
"properties" : {
"name" : {
"type" : "string"
},
"age" : {
"type" : "integer"
}
}
}
}
}
or the similar with the sheep, basically, the concrete class of Animal
However, I am getting this: (Actual result)
{
"type" : "object",
"id" : "urn:jsonschema:com:schema:Farm",
"properties" : {
"name" : {
"type" : "string"
},
"capacity" : {
"type" : "integer"
},
"animal" : {
"type" : "object",
"id" : "urn:jsonschema:com:schema:Animal"
}
}
}
I went through the list of examples in TestGenerateJsonSchema class, however, it seems there is no example showing a nested class with concrete implementation of interface.
May I ask how to generate the schema for a nested class please?
Thank you
Our issue tracker is not for answering usage questions. Use stackoverflow or mail the jackson user mailing list - https://groups.google.com/g/jackson-user
Please also read https://github.com/FasterXML/jackson-module-jsonSchema#future-plans-lack-thereof
This module is not actively maintained. You might be better off seeking alternative libs.