Hi, I'm working with CXF 2.7.7 for JAX-WS and and having trouble with the
de-serialization of an Enum. We recently upgraded many of libraries, and
this particular code was not modified, so I'm guessing the handling of
Enums has changed enough that it breaks our current code.
I can add more details if needed, but the crux of the issue seems to be:
Looking at the data via Wireshark, the SOAP body comes in with
-snip-
<type>AREA</type>
-snip-
For a method with a signature:
createArea(int arg1, int arg2, AreaType type, int arg4, CustomObject[]
objects)
Everything serializes fine, but the AreaType instance comes through as null.
I've attempted to add XML binding annotations to the AreaType to no avail.
I also added an XmlAdapter to see if that would aid in the conversion. No
luck there.
This is very hard to test in isolation. I can successfully unmarshal
<type>AREA</type> with a simple test as recommended in a separate thread by
a JAXB/Moxy programmer after adding XmlRootElement annotation to the enum.
I came across anther post recommending a no-arg constructor in order for
JAXB to unmarshal, but the fact that the test below unmarshals it
correctly, makes me think something is up with CXF.
==== TEST ====
public class JaxbUnmarshallerTest {
private static final String XML = "<areaType>AREA</areaType>";
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(AreaType.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setEventHandler(new ValidationEventHandler() {
@Override
public boolean handleEvent(ValidationEvent validationEvent) {
System.out.println(validationEvent.getMessage());
//validationEvent.getLinkedException().printStackTrace();
return true;
}
});
AreaType root = (AreaType) unmarshaller.unmarshal(new StringReader(
XML));
System.out.print(root.toString());
}
}
==== END TEST ====
Here is the AreaType enum:
public enum AreaType {
CAMPUS(null),
BUILDING(CAMPUS),
FLOOR(BUILDING),
AREA(FLOOR),
ROOM(AREA),
SUBROOM(ROOM);
private final AreaType parent;
private static Map<String, AreaType> stringToEnum = new HashMap<String,
AreaType>();
static {
for(AreaType t : values()) {
stringToEnum.put(t.toString(), t);
}
}
private AreaType(AreaType parent) {
this.parent = parent;
}
public AreaType getChild() {
for(AreaType t : values()) {
if(this == t.getParent()) {
return t;
}
}
return null;
}
public AreaType getParent() {
return parent;
}
public static AreaType fromString(String type) {
return stringToEnum.get(type);
}
public static AreaType fromValue(String type) {
return stringToEnum.get(type);
}
}