Java 为什么fasterxml失去了;xsi:type";属性,但JAXB封送器没有问题

Java 为什么fasterxml失去了;xsi:type";属性,但JAXB封送器没有问题,java,xml,jaxb,jackson,fasterxml,Java,Xml,Jaxb,Jackson,Fasterxml,当我向抽象xsd类添加@XmlSeeAllow注释时,原始JAXB封送器工作正常 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Service xmlns="http://www.a.com"> <animal xsi:type="Dog" holder="Apache" name="Tomcat" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in

当我向抽象xsd类添加@XmlSeeAllow注释时,原始JAXB封送器工作正常

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Service xmlns="http://www.a.com">
    <animal xsi:type="Dog" holder="Apache" name="Tomcat" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</Service>
测试用例

@Test
public void testXsiType() throws Exception {
    Service service = new Service();
    Dog dog = new Dog();
    service.setAnimal(dog);
    dog.setName("Tomcat");
    dog.setHolder("Apache");

    JAXBContext jaxb = JAXBContext.newInstance(Service.class, Dog.class);
    Marshaller marshaller = jaxb.createMarshaller();
    StringWriter writer = new StringWriter();
    marshaller.marshal(service, writer);
    System.out.println(writer.toString());

    ObjectMapper serializer = new XmlMapper();
    serializer.registerModule(new JaxbAnnotationModule());
    serializer.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    serializer.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);

    System.out.println(serializer.writeValueAsString(service));

}
我用的lib

<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.4.5</version>
</dependency>

com.fasterxml.jackson.dataformat
jackson数据格式xml
2.4.5
@Test
public void testXsiType() throws Exception {
    Service service = new Service();
    Dog dog = new Dog();
    service.setAnimal(dog);
    dog.setName("Tomcat");
    dog.setHolder("Apache");

    JAXBContext jaxb = JAXBContext.newInstance(Service.class, Dog.class);
    Marshaller marshaller = jaxb.createMarshaller();
    StringWriter writer = new StringWriter();
    marshaller.marshal(service, writer);
    System.out.println(writer.toString());

    ObjectMapper serializer = new XmlMapper();
    serializer.registerModule(new JaxbAnnotationModule());
    serializer.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    serializer.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);

    System.out.println(serializer.writeValueAsString(service));

}
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
    <version>2.4.5</version>
</dependency>