嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法构造 `com.xyz.pqr.model.Date` 的实例

nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.xyz.pqr.model.Date`

错误:

我使用 JAXB 从 XSD 生成了 Java POJO。现在我正在尝试使用 XML 负载。但我 运行 进入以下内容:

"Bad Request","message":"JSON parse error: Cannot construct instance of com.xyz.pqr.model.Date (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('01/01/2012'); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.xyz.pqr.model.Date (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('01/01/2012')\n at [Source: (PushbackInputStream); line: 1, column: 3419] (through reference chain: com.xyz.pqr.model.DATA[\"residentAddress\"]->com.xyz.pqr.model.Address[\"fromDate\"])","path":"/receiveXML"} .

控制器:

    @PostMapping(path="/receiveXML", consumes="application/xml")
    public String receiveXml(@RequestBody DATA xml) {

        return "XML Received";
    }

卷曲:

curl -X POST --header "Content-Type:application/xml;charset=UTF-8" --data @soap_get.xml http://localhost:8080/receiveXML

谁能给我指出正确的方向?我是否需要某种绑定文件来将字符串解析为日期?

杰克逊依存关系:

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

DATA 中的地址字段 @XML根元素 public class 数据

protected Address residentAddress; -- 这个没有注释

地址内的日期class: @XmlElement(必需=真) 保护日期 fromDate;

XSD:

<xs:complexType name="address">
 \
 \
   <xs:element name="fromDate" type="date"/>
\
\
<xs:complexType name="address">


<xs:complexType name="date">
<xs:simpleContent>
<xs:extension base="dateBase">
<xs:attribute name="formatString">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="shortDate">
<xs:annotation>
<xs:documentation>equivalent of MM/dd/yyyy</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="MM/dd/yyyy"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

通过删除我放在上面的所有 jackson 依赖关系解决了这个问题。