Open cowtowncoder opened 10 years ago
What's the status of this? From my experience, it looks like I can successfully create a schema from an object and then turn that into a json string, but then if I use an ObjectMapper to turn that back into a JsonSchema, all of my arrays get messed up. That's a big problem for me.
Is there anything I can do to help fix this or make the fix happen sooner?
I haven't had time to work on Schema module lately, so any help would be appreciated.
Oftentimes the problem is in databind module, since most information is sent by JsonSerializer
that handles the property. It is also possible that information piped through BeanPropertyWriter
is incomplete. And of course, finally, it is also possible that JSON Schema visitors could be omitting something; but more commonly it is incoming metadata that is incomplete.
I'm afraid I'm not familiar enough with the code to fix it myself :-( I did a bit of debugging and comparing, and it certainly seemed like the two JsonSchemas (the original, and the one created from its string output) were different from each other and the second one had the oversimplified array items. So it seems to me that the problem is somewhere in converting the String to a JsonSchema, not in analyzing that JsonSchema.
Best guess is that the problem is in the com.fasterxml.jackson.module.jsonSchema.types.ArraySchema file, in Items.jsonCreator. I see a comment in there about another bug too.
@mariepaulsen-sersol I'll go and have a look at the updated tests; sometimes there are easy fixes to be found.
Oh . . . you were talking about serializing, I think the problem is in the deserialization of a schema json string into a JsonSchema object. My sequence:
1.
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(mapper.constructType(Foo.class), visitor);
JsonSchema schema = visitor.finalSchema();
String schemaString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
log.debug(schemaString);
"foo" : {
"type" : "array",
"items" : {
"type" : "object",
"id" : "urn:jsonschema:com:company:project:stuff:Bar",
"properties" : {
"baz" : {
"type" : "string"
}
}
}
}
ObjectMapper objectMapper = new ObjectMapper();
JsonSchema secondSchema = objectMapper.readValue(Experiment.class.getResource("/schema.json"), JsonSchema.class);
ObjectMapper secondMapper = new ObjectMapper();
String secondSchemaString = secondMapper.writerWithDefaultPrettyPrinter().writeValueAsString(secondSchema);
log.debug(secondSchemaString);
"foo" : {
"type" : "array",
"items" : {
"type" : "object",
}
}
Ah. This may be different from the original problem then, which was wrt to generation of schema. I wouldn't be surprised if there were issues with deserialization, as much less effort has been put there. I'll see if I can figure out the problem, regardless; schema should deserialize back without losing content.
Any news on this problem? I run into the same issue if it try to parse a ArraySchema all getItems() property fields are null. I am using version 2.6.1
Hi, any progress with this? It's a notable gap in functionality.
@dazraf This modules does not have maintainer, and unless someone steps up it will probably be dropped from FasterXML repo for 3.0. There are better generators out there.
But if anyone wants to do a PR I can help merge.
NOTE: cleaved off of #34
This bug seems not to be completely fixed. It doesn't throw a NPE anymore, but it doesn't generate the schema correctly either. It just generates:
I extended the test to use a collection of nested beans, and expected to see the schema of the nested items, e.g.:
See updated test: https://github.com/greyfairer/jackson-module-jsonSchema/commit/2a9b859fac14a412de68917655c9cf928d31d651