I have a code which was working fine with Spring boot 2 but when i moved it to spring 3, I get an error message saying
java.lang.IllegalArgumentException: Cannot deserialize value of type `java.time.Instant` from Object value (token `JsonToken.START_OBJECT`) at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: java.util.ArrayList[0]->com.oxane.argon.kpi.KpiFieldDTO["lastModifiedDate"])
I have a query which was quite complex and uses many joins and CTE after that I fetch limited data from a POJO table. So I use NamedParameterJdbcTemplate to fetch list of result after that I convert List<Map<String,Object>> to my DTO using object mapper, which was working fine before spring 2 now I receive the above error. Data for Instant field is stored as Datetimeoffset in DB because I haven’t added any line for backward compatibility.
My DTO looks like this
public class dDTO {
private String loanId;
private String obligor;
private LocalDate fsDateLatest;
private LocalDate lastUpdate;
private Instant createdDate;
private Instant lastModifiedDate;
private Integer investmentType;
private LocalDate maturityDate;
private String reportingCurrency;
private BigDecimal debtWeightedSpread1L;
private Integer lastModifiedBy;
private String lastModifiedByEmail;
//getters and setters and constructors
}
Code to convert data
List<Map<String, Object>> kpiByObligorAndFs;
final List<DTO> findAllByObligorAndFsDateLessThanEqual = objectMapper.convertValue(kpiByObligorAndFs, new TypeReference<List<DTO>>() {
});