你好,我需要配置fastxml。Jackson序列化器完全像默认JAXB序列化器一样工作。
我有以下两个类的情况:
@XmlRootElement(name = "elA")
public class A {
@XmlElementRef
public Collection<B> getBs() {
return this.bs;
}
}
@XmlRootElement(name = "elB")
public class B {
}
我的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>
我应该如何配置对象映射器来获得预期的结果?谢谢你!
我不能更改类和注释,因为这是框架的一部分。
我唯一能影响的是ObjectMapper和Jackson的配置
@XmlRootElement(name = "elA")
public class ElA{
@XmlElementRef
public Collection<B> getElB() {
return this.elb;
}
}
@XmlRootElement(name = "elB")
public class ElB{
}