[英]Could not deserialize object. Failed to convert value of type java.util.Date to String
[英]Cannot deserialize value of type `java.util.Date` from String
使用Spring 1.5.8.RELEASE Jackson mapper給出以下異常。
Cannot deserialize value of type `java.util.Date` from String "2018-09-04T10:44:46": expected format "yyyy-MM-dd'T'HH:mm:ss.SSS"
在[來源:UNKNOWN; line:-1,column:-1](通過引用鏈:com.copart.conversationapi.calldisposition.model.vo.CallLogEntity [“callEndTime”])
CallEntity.java
@JsonProperty("callEndTime")
@Column(name = "call_end_ts")
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS")
private Date callEndTime;
DAO.java
ObjectMapper mapper = new ObjectMapper();
HashMap<String, Object> finalHashMap;
finalHashMap = convertMultiToString(requestMap);
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
CallLogEntity callLogEntity = mapper.convertValue(finalHashMap, CallEntity.class);
的pom.xml
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
將@JsonFormat
行更改為此。
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
您現在擁有的格式模式希望sting具有毫秒值 - 但您的示例字符串沒有它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.