英文:
Jackson deserialize date string with + and t character
问题
我在反序列化 JSON 字符串日期时遇到问题:2020-09-30T07:00:00+02:00
我收到了错误消息:
com.fasterxml.jackson.databind.exc.InvalidFormatException: 无法从字符串 "2020-09-30T07:00:00+02:00" 反序列化为类型 `java.time.LocalDate`:无法反序列化 java.time.LocalDate:(java.time.format.DateTimeParseException) 无法解析文本 '2020-09-30T07:00:00+02:00',在索引 19 处找到未解析的文本
看起来好像是 + 符号是一个意外的字符。
POJO:
@JsonProperty("Date")
@JsonDeserialize(using = LocalDateDeserializer.class)
public LocalDate date;
有任何想法如何将这个字符串映射到 LocalDate 类型吗?
英文:
i have problem with deserialize Json string date: 2020-09-30T07:00:00+02:00
I am getting error:
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDate` from String "2020-09-30T07:00:00+02:00": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '2020-09-30T07:00:00+02:00' could not be parsed, unparsed text found at index 19
Its look like + is and unexcepted character.
Pojo:
@JsonProperty("Date")
@JsonDeserialize(using = LocalDateDeserializer.class)
public LocalDate date;
Any ideas how i can map this string to localdate?
答案1
得分: 1
这应该可以运行
@JsonProperty("Date")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
public LocalDate date;
在这里查看日期格式:https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
此外,你应该使用另一种类型,如ZonedDateTime或java.util.Date,而不是LocalDate,以获得小时、分钟和秒。
英文:
This should work
@JsonProperty("Date")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
public LocalDate date;
Check DateFormat here: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
Besides you should use another type like ZonedDateTime or java.util.Date instead of LocalDate to get hour, minute and second.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论