yasson icon indicating copy to clipboard operation
yasson copied to clipboard

EnumMap (de)serializing issues

Open nimo23 opened this issue 6 years ago • 1 comments
trafficstars

When using an EnumMap:

JsonbBuilder.create().fromJson(json, new EnumMap<TYPE, Task>(TYPE.class) {
private static final long serialVersionUID = -3762002712427352481L;}.getClass());

I get this error:

javax.json.bind.JsonbException: Can't create instance of a class: class java.util.EnumMap, No default constructor found.

nimo23 avatar Aug 04 '19 10:08 nimo23

hi @nimo23 thanks for raising this issue. EnumMap isn't required by the JSON-B spec but since it's part of the JDK I think we can add a default adapter for it.

I've raised a PR (#295) which adds support for EnumMap. However, it doesn't allow the original code example you posted to work as-is. In order to deserialize a generic collection, you will need to call getGenericSuperClass() at the end like this:

JsonbBuilder.create().fromJson(json, new EnumMap<TYPE, Task>(TYPE.class) {
  private static final long serialVersionUID = -3762002712427352481L;
}.getClass().getGenericSuperclass());

aguibert avatar Aug 05 '19 21:08 aguibert