jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Support object enum

Open ben-manes opened this issue 3 years ago • 2 comments

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.

ben-manes avatar Nov 30 '20 22:11 ben-manes

+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 :(

tillias avatar Mar 30 '21 07:03 tillias

  • 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 ?

unkish avatar Jul 31 '21 18:07 unkish