使用eclispelink时,嵌套的@XmlJavaTypeAdapter注释被忽略,其中嵌套对象是通用的
||
编组对象树时,我使用的是
@XmlJavaTypeAdapter
。一些适配器返回本身带有“ 0”注释的类的对象。当我使用与Websphere 7打包在一起的JAXB实现时,这很好用,但是当我使用org.eclipse.persistence.jaxb.JAXBContextFactory
时,第一个适配器返回的对象上的@XmlJavaTypeAdapter
注释将被忽略。这是一个已知问题,还是我做错了什么?
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class,C.class);
System.out.println(jc.getClass());
Root root = new Root();
A a = new A();
root.a = a;
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
}
根
@XmlRootElement
public class Root {
@XmlJavaTypeAdapter(AAdapter.class)
public A a;
}
一种
public class A {
public B b = new B();
}
乙
public class B {
@XmlJavaTypeAdapter(GAdapter.class)
@XmlElement(name=\"b\")
public G<C> gc = new G<C>();
public B(){
gc.t = new C();
}
}
C
public class C {
public String c = \"Foo\";
}
G
public class G<T> {
T t;
}
然后是ѭ10的适配器...
public class AAdapter extends XmlAdapter<B, A> {
@Override
public A unmarshal(B b) throws Exception {
A a = new A();
a.b = b;
return a;
}
@Override
public B marshal(A a) throws Exception {
return a.b;
}
}
和通用类型的适配器
public class GAdapter<T> extends XmlAdapter<T, G<T>> {
@Override
public G<T> unmarshal(T c) throws Exception {
return new G<T>();
}
@Override
public T marshal(G<T> g) throws Exception {
return g.t;
}
}
mar13级时被封送
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<root>
<a>
<b xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"c\">
<c>Foo</c>
</b>
</a>
</root>
与org.eclipse.persistence.jaxb.JAXBContext
在一起时
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<root>
<a>
<b>forum237.C@23752375</b>
</a>
</root>
我认为问题在于泛型类型。目标是跳过通用类型,仅封送T
,并处理T
的注释(如果有)。
没有找到相关结果
已邀请:
1 个回复
畦桨存灯
一种
适配器
乙
演示版
输出量
预期产量