项目在Maven中有spring-boot-starter-web starter。
我在项目中看到了这些问题
jackson datatype-jdk 8-2.10.1 jackson-datatype-jsr310-2.10.1
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class BillingEvent {
public Long Id;
public LocalDate billingCreatedDate;
}
InvalidDefinitionException:无法构造java.time.localdate
的实例(没有创建者,如默认构造,存在):没有字符串参数构造函数/工厂方法可以从字符串值反序列化('2019-09-02')
对我来说,在BillingEvent
中添加setter就足够了,比如:
public void setBillingCreatedDate(String str) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
billingCreatedDate = LocalDate.parse(str, formatter);
}
有关格式化的更多信息,请参见:String to LocalDate
根据评论:
public class LocalDateDeserializer extends JsonDeserializer<LocalDate> {
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Override
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
return LocalDate.parse(p.readValueAs(String.class), formatter);
}
}
@JsonDeserialize(using = LocalDateDeserializer.class)
public LocalDate billingCreatedDate;