Skip to content
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

Support object enum #1181

Open
ben-manes opened this issue Nov 30, 2020 · 2 comments
Open

Support object enum #1181

ben-manes opened this issue Nov 30, 2020 · 2 comments

Comments

@ben-manes
Copy link
Collaborator

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.

@tillias
Copy link

tillias commented Mar 30, 2021

+1
Can be solved from business perspective as #1193 (comment) with oneOf, but generator will still generate empty class :(

@unkish
Copy link
Collaborator

unkish commented Jul 31, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants