我有一个 Dto 类,它将设置一个值 LocalDateTime
作为数据类型。
接收 JSON 时出现错误。
public class Dto {
@JsonFormat(shape = JsonFormat.Shape.STRING)
private LocalDateTime scheduledStartTime;
}
}
这是错误:
Cannot construct instance of `java.time.LocalDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-08-01T15:30:00Z')
最佳答案
尝试禁用:
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
或
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonSerialize(using = LocalDateTimeSerializer.class)
关于java - 序列化收到的数据类型为 'LocalDateTime' 的 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57903494/