【发布时间】:2020-06-17 15:34:58
【问题描述】:
我有一个侦听主题的队列,并且我的侦听器接收到 DTO。
我需要将字符串解析为LocalDateTime,但出现此错误
org.springframework.messaging.converter.MessageConversionException: Could not read JSON: Text '2020-06-18 11:12:46' could not be parsed at index 10
这是消息详情
{"id":444, "details":{"TYPE":[1]},"dateOccurred":"2020-06-18 11:12:46"}"]
这是我在 DTO 中的设置方式
public class PlanSubscriptionDto {
private Long id;
private Map<String, List<Long>> details;
private LocalDateTime dateOccurred;
public void setDateOccurred(String dateTime) {
this.dateOccurred = LocalDateTime.parse(dateTime, DateTimeFormatter.ISO_DATE_TIME);
//ive also tried this
//this.dateOccurred = LocalDateTime.parse(dateTime, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG));
}
}
感谢您的帮助! 任何建议都会很棒。
【问题讨论】:
标签: java spring-boot localdatetime