Search code examples
javajaxbxmladapter

Xml Java adapter not working properly


Require help: following XmlJavaTypeAdapter type is not working properly:

public class TestAdapter extends XmlAdapter<Object, Object> {

 public Object marshal(Object arg0) throws Exception {
  System.out.println("Test Adapter");
  return null;
 }

 public Object unmarshal(Object arg0) throws Exception {
  System.out.println("Test Adapter");
  return null;
 }
}

I am using the "TestAdapter" like :

'@XmlRootElement
 @XmlJavaTypeAdapter(value = TestAdapter.class)
 public TestClass{...}'

But the problem I am facing is the "TestAdapter" is never getting invoked.


Solution

  • XmlAdapter does not apply on root elements.

    And i don't think there's an implementation of JAXB that is able to do it.

    See : Using an adapter to marshal a class to a root element with MOXy or any other JAXB implementation

    As said in the linked topic, you can apply your adapter logic manually to workaround your problem.