赞
踩
报错如下:
Bad Request: JSON parse error: Cannot deserialize value of type `java.time.LocalDate` from String "2020-1-2": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '2020-1-2' could not be parsed at index 5; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDate` from String "2020-1-2": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '2020-1-2' could not be parsed at index 5
at [Source: (PushbackInputStream); line: 8, column: 15] (through reference chain: com.ledar.mono.domain.Patient["birthday"])
java 中 Instant
类型的数据在 swagger 上进行测试时 以json
格式输入时格式为2018-07-09T08:59:08.853Z
java 中 LocalDate
类型的数据在 swagger 上进行测试时 以json
格式输入时格式为2018-07-09
,需要特别注意的是,07和09是两位数字,不是一位数字。
如果导包正确的话(Jackson的包,将String 与JSON格式正反序列化,互相转换),不需要作如下配置
/**
* 出生日期
*/
@Schema(description = "出生日期")
@Column(name = "birthday")
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
@JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd")
private LocalDate birthday;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。