jakartaee / jsonb-api

Jakarta JSON Binding
https://eclipse-ee4j.github.io/jsonb-api/
Other
79 stars 39 forks source link

Add support for EnumMap and EnumSet #186

Open aguibert opened 5 years ago

aguibert commented 5 years ago

The classes java.util.EnumSet and java.util.EnumMap are part of the JDK and could be supported by JSON-B.

EnumSet should certainly be supported because JSON-B already support collections of POJOs, and EnumSet only doesn't work because it doesn't have any standard constructors.

EnumMap could also be considered. Technically JSON-B currently only supports java.lang.String keys, but Enums are quite easy to translate to/from String values. This could also potentially expand into a larger effort to support "stringable" keys as defined by Section 3.2 of the JAX-RS 2.1 spec:

Valid parameter types for each of the above annotations are listed in the corresponding Javadoc, however in general (excluding @Context) the following types are supported:

  1. Types for which a ParamConverter is available via a registered ParamConverterProvider. See Javadoc for these classes for more information.
  2. Primitive types.
  3. Types that have a constructor that accepts a single String argument.
  4. Types that have a static method named valueOf or fromString with a single String argument that return an instance of the type. If both methods are present then valueOf MUST be used unless the type is an enum in which case fromString MUST be used1.
  5. List, Set, or SortedSet, where T satisfies 1, 3 or 4 above.
aguibert commented 5 years ago

Currently the JSON-B TCK tests that EnumMap/EnumSet do NOT work, which I believe is an invalid test and JSON-B should in fact be required to support it.

TCK issue: https://github.com/eclipse-ee4j/jakartaee-tck/issues/103