I already went through link: JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value, but getting below error.
Error:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.Instant` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-08-28T15:15:44.183Z')
Java
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class StudentResponse {
private Integer a;
private String b;
private String c;
private String d;
private String e;
private Instant lastUpdateDate;
}
I was able to parse a JSON where Instant
field is "2019-08-28T15:15:44.183Z"
First of all, ensure you have a dependency. E.g. in build.gradle
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
Then configure ObjectMapper
to use this dependency and not (de)serialize Instant
as timestamps that it does by default. I setup my ObjectMapper
as:
ObjectMapper mapper = new ObjectMapper()
.findAndRegisterModules()
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With