这里回答了类似的问题.您可能需要添加@JsonSerialize(using = LocalDateTimeSerializer.class)
到您的字段中.
您还可以创建如下的自定义序列化程序:
public class CustomLocalDateTimeSerializer extends JsonSerializer{ @Override public void serialize(LocalDateTime dateTime, JsonGenerator generator, SerializerProvider sp) throws IOException, JsonProcessingException { String formattedDateTime = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); generator.writeString( formattedDateTime); } }
并在LocalDateTime字段中使用该自定义序列化程序:
@JsonSerialize(using = CustomLocalDateTimeSerializer.class) private LocalDateTime w_date;