-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid serialisation of UnionTypeSchema #90
Comments
This is tricky due to multiple reasons; one being that |
Hmmmh. Was about to add The thing is, serialization of Type Id by Jackson will never be able to produce arbitrary structures; so if true union types are desired, handling MUST be completely rewritten. And specifically, I don't think there will ever be support to use/consume JSON Array of type ids. If anyone cares enough to work on this (I basically do not use JSON Schema myself, and do not have personal interest, beyond hoping to help others), I think the model to follow would be delegation/converter, so that intermediate value would be One challenge is that such a change would be backwards compatible only via JSON produced/consumed, as type of |
We're using JSON schema quite extensively for self-describing REST APIs (with self-building web CRUD UIs), although we're only using serialization. As it seem like we're the only people in the world actually using this, I'd be happy to try a fork and submit some pull requests that address some of the issues we've had. |
@tapina That would be great. I should be able to help with details at least; and having unit tests is a good first step any way; we can add them under |
Enums can certainly be a pain. Indeed to work around one of the limitations of the module around value formats I had to create some horrible code to dynamically modify the relevant enum at runtime (who knew you even could?!). Being able to contribute some code to the project to get rid of that monstrosity would take away the bitter taste that lingers with me... Gareth
|
Yeah, enums are a tricky choice. Impressive hack on replacing enums at runtime, did not realize that is possible. One can at least make enums implement an interface, which is sometimes useful for finding balance between extensibility... but there are many limitations. |
UnionTypeSchema currently cannot be serialised because it returns a null type which is not welcomed by JsonSchemaIdResolver.idFromValue. If you extend UnionTypeSchema and return a type then it serialises this as "type" and serialises the types as "elements". This is not valid JSON Schema. It should serialize the union as a "type" array. See https://tools.ietf.org/html/draft-zyp-json-schema-03#page-8
If I then attempt to further patch UnionTypeSchema to change "elements" into "type" then it serialises with TWO "type" properties which isn't even valid JSON!
If I attempt to annotate UnionTypeSchema to not include type info with @JsonTypeInfo(use = JsonTypeInfo.Id.NONE, property = "type") then it has no effect except when the union type schema is passed directly to ObjectMapper.
A test case is attached.
JacksonUnionTypeSerializationBugTest.java.txt
The text was updated successfully, but these errors were encountered: