我正在尝试使用XMLmapper反序列化xml,但失败并出现以下错误。 POJO是使用jaxb XJC工具生成的,同时解决了依赖项。如果我使用jaxb Unmarhsalling,则相同的反序列化将顺利通过。我对xsds没有任何控制。有人可以帮忙吗?我尝试添加绑定以生成没有帮助的单独的程序包名称。我认为我无法重命名该属性,因为从上游接收XML时xml可能会失败。 有什么建议吗?
表示属性“ PaymentPlanID”的多个字段:om.datatype.defn.v1.PaymentDetailDataType#paymentPlanID与om.datatype.defn.v1.PaymentDetailDataType#paymentPlanIDV2
以下代码有效
jaxbContext = JAXBContext.newInstance(EventsRequestType.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
InputStream is = new ByteArrayInputStream(input.getBytes());
EventsRequestType outputRequest = ((JAXBElement<EventsRequestType>) jaxbUnmarshaller.unmarshal(is)).getValue();
这不起作用
jacksonXmlModule jacksonXmlModule = new JacksonXmlModule();
jacksonXmlModule.setDefaultUseWrapper(false);
MAPPER = new XmlMapper(jacksonXmlModule);
MAPPER.registerModule(new JaxbAnnotationModule());
EventsRequestType outputRequest = MAPPER.readValue(input, EventsRequestType.class);
JAXB生成的pojo中的文件
@XmlElement(name = "PaymentPlanID", namespace = "urn:payment:messages:v1")
protected String paymentPlanID;
@XmlElement(name = "PaymentPlanID", namespace = "urn:payment:processor:messages:v2")
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlSchemaType(name = "token")
@Size(min = 1)
protected String paymentPlanIDV2;
xsd的提取物
<xs:complexType name="PaymentDetailDataType">
<xs:complexContent>
<xs:extension base="data:BaseDataType">
<xs:sequence>
<xs:choice>
<xs:element ref="payment:PaymentPlanID">
</xs:element>
<xs:element ref="payment_v2:PaymentPlanID">
<xs:annotation>
<xs:appinfo>
<jaxb:property name="PaymentPlanIDV2"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required">
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>