Require help: following XmlJavaTypeAdapter type is not working properly:
需要帮助:以下XmlJavaTypeAdapter类型无法正常工作:
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 :
我正在使用“TestAdapter”,如:
'@XmlRootElement
@XmlJavaTypeAdapter(value = TestAdapter.class)
public TestClass{...}'
But the problem I am facing is the "TestAdapter" is never getting invoked.
但我面临的问题是“TestAdapter”永远不会被调用。
1 个解决方案
#1
1
XmlAdapter does not apply on root elements.
XmlAdapter不适用于根元素。
And i don't think there's an implementation of JAXB that is able to do it.
我认为没有JAXB的实现能够做到这一点。
See : Using an adapter to marshal a class to a root element with MOXy or any other JAXB implementation
请参阅:使用适配器使用MOXy或任何其他JAXB实现将类封送到根元素
As said in the linked topic, you can apply your adapter logic manually to workaround your problem.
如链接主题中所述,您可以手动应用适配器逻辑来解决问题。
#1
1
XmlAdapter does not apply on root elements.
XmlAdapter不适用于根元素。
And i don't think there's an implementation of JAXB that is able to do it.
我认为没有JAXB的实现能够做到这一点。
See : Using an adapter to marshal a class to a root element with MOXy or any other JAXB implementation
请参阅:使用适配器使用MOXy或任何其他JAXB实现将类封送到根元素
As said in the linked topic, you can apply your adapter logic manually to workaround your problem.
如链接主题中所述,您可以手动应用适配器逻辑来解决问题。