您好我需要将fastxml.Jackson Serializer配置为与默认的JAXB Serializer完全兼容。
我有两个类的以下案例:
@XmlRootElement(name = "elA")
public class A {
@XmlElementRef
public Collection<B> getBs() {
return this.bs;
}
}
@XmlRootElement(name = "elB")
public class B {
}
My Object Mapper配置如下所示:
XmlMapper objectMapper = new XmlMapper();
JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
objectMapper.registerModule(jaxbAnnotationModule);
objectMapper.setDefaultUseWrapper(false);
objectMapper.configure(SerializationFeature.INDENT_OUTPUT,true);
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE,false);
objectMapper.configure(SerializationFeature.CLOSE_CLOSEABLE, true);
objectMapper.setSerializationInclusion(Include.NON_ABSENT);
JaxbAnnotationIntrospector jaxbAnnotationIntrospector = new XmlJaxbAnnotationIntrospector(objectMapper.getTypeFactory());
objectMapper.setAnnotationIntrospector(jaxbAnnotationIntrospector);
我需要为Jackson Serializer配置ObjectMapper以生成以下XML
<elA>
<elB></elB>
<elB></elB>
</elA>
但我明白了:
<A>
<bs></bs>
<bs></bs>
</A>
如何配置Object Mapper以获得预期结果?谢谢。
我不能改变类和注释,因为这是框架的一部分。
我唯一可以影响的是ObjectMapper和Jackson配置。
答案 0 :(得分:0)
@XmlRootElement(name = "elA")
public class ElA{
@XmlElementRef
public Collection<B> getElB() {
return this.elb;
}
}
@XmlRootElement(name = "elB")
public class ElB{
}