Please consider the following example:
There is ClassA and ClassB that extends it. My problem is that I need to undo the ClassB token from the xml file. Please note that ClassA cannot be changed since it is not under my control.
There are several problems noted in this example:
The main problem is that ClassA does not have a default no-arg constructor, which is required by JAXB without an adapter. So I implemented MyAdapter , which maps ClassB to a simple ValB class that can be handled by JAXB without problems.
The main problem is how to get JAXB to use this adapter? Neither the definition of @XmlJavaTypeAdapter at the class level, nor the registration of the adapter for a non-marshaller do.
Does anyone know how to get JAXB to use MyAdapter so that unmarshaller returns an object that is an instance of ClassA ?
public class JaxbTest { public static abstract class ClassA { public ClassA(String id) { } } @XmlRootElement @XmlJavaTypeAdapter(MyAdapter.class)
BTW: Don't take the code too seriously - this is just an example that demonstrates the problem. I know that defining ClassA and ClassB is not very useful.
java constructor adapter jaxb unmarshalling
Robert
source share