yasson
yasson copied to clipboard
EnumMap (de)serializing issues
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.
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());