you are getting that error since Json is trying to deserialize the date sting into instance of LocalDateTime but it not being able to do that due no constructor or such method on that class.
You can get to solution by creating a custom deserializer class by extending JsonDeserializer and override the deserializer method and return to required by Parsing.
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
public class CustomLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
@Override
public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
String dateStr = jsonParser.getValueAsString();
return LocalDateTime.parse(dateStr, formatter);
}
}
Then annotate the field with custom deserializer instead.
@JsonDeserialize(using = CustomLocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
public LocalDateTime date;
I am sure that you have this dependency.
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
Hope this works for you. I did have get some shortcut just before 3-4 months. Sorry I forgot that.
Tin the middle rather than the SPACE seen in your text:2023-09-22T02:11:13.855618. I guess you either need to correct your inputs to comply with ISO 8601 or you need to configure Jackson with a formatter to parse your particular inputs. en.wikipedia.org/wiki/ISO_8601