Skip to content

Cannot deserialize object with EnumMap #1907

@fabianfrz

Description

@fabianfrz

Hi,

there is an issue when using classes that use an EnumMap as a map implementation:

Caused by: java.lang.NoSuchMethodError: java.util.EnumMap.<init>()
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.core.v2.ClassFactory.tryGetDeclaredConstructor(ClassFactory.java:117)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.core.v2.ClassFactory.create0(ClassFactory.java:78)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.core.v2.ClassFactory.create(ClassFactory.java:130)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.property.SingleMapNodeProperty$1.startElement(SingleMapNodeProperty.java:129)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:530)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:509)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:217)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:149)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:376)
	at org.glassfish.jaxb@4.0.5.redhat-00001//org.glassfish.jaxb.runtime.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:355)
	at org.apache.cxf.impl//org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:880)
	at org.apache.cxf.impl//org.apache.cxf.jaxb.JAXBEncoderDecoder$3.run(JAXBEncoderDecoder.java:919)

In case of an EnumMap, you cannot use a default constructor because it does not exist, the enum needs to be passed down as the first argument. Since this is a JDK-Internal and linters such as Sonarqube suggest using it, It would be good if this special case could be handled.

This happens on a JBoss 8.1 application server and as you can see on calling an endpoint using CXF.

For example if you have an enum Alphabeth, you would make it look like this:

var x = new EnumMap<Alphabeth, String>(Alphabeth.class);
x.put(Alphabeth.A, "Test");

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions