Я объявил переменные как localdate в моем классе pojo. Я сделал все, но моя дата конвертируется в гггг-мм-дд, но я хочу прочитать дд / мм / гггг. Я сделал все записи пом. Прошло 2 дня, но я не могу решить эту проблему. Я использую objectMapper.getTypeFactory (). ConstructCollectionType для анализа списка.
@JsonFormat(pattern = "dd/MM/yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
private LocalDate date;
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Constant.dateFormat);
protected LocalDateDeserializer() {
super(LocalDate.class);
}
@Override
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
return LocalDate.parse(jp.readValueAs(String.class), formatter);
}
public LocalDateSerializer() {
super(LocalDate.class);
}
@Override
public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider sp)
throws IOException, JsonProcessingException {
gen.writeString(value.format(DateTimeFormatter.ofPattern(Constant.dateFormat)));
}
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);