jsonschema2pojo
jsonschema2pojo copied to clipboard
Support object enum
JsonSchema allows for enumerations of objects, not just strings. For complex workflows this is very beneficial, e.g.
"status": {
"type": "object",
"properties": {
"foo": {
"type": "string",
},
"bar": {
"type": "string",
}
},
"enum": [
{ "foo": "1", "bar": "A" },
{ "foo": "2", "bar": "B" },
{ "foo": "3", "bar": "C" }
]
}
Unfortunately the generated code will look something like,
enum Status {
__EMPTY__(null),
__EMPTY___(null),
__EMPTY____(null);
...
}
For now this cannot be done by type-safe generated code, but manually kept in sync.
+1 Can be solved from business perspective as https://github.com/joelittlejohn/jsonschema2pojo/issues/1193#issuecomment-809970916 with oneOf, but generator will still generate empty class :(
- in case of enum definition without extensions as provided in sample - what would the expected enum constant names be instead of
__EMPTY__
? - how would serialized form look like ?
- enum constant name (as with non-object enums)
- object form (enum properties)
- would that be a jackson-json specific feature or other JSON libraries like moshi, gson, etc. are able to support enum object serialization/deserialization "out of the box" ?
- some other form ?
- any restrictions that might exist ?