I get this error when attempting to deserialize but I feel there is a deserializing interface i need to configure.
The error:
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.sql.Timestamp` from String "2022-01-13 23:57:58": not a valid representation (error: Failed to parse Date value '2022-01-13 23:57:58': Cannot parse date "2022-01-13 23:57:58": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
at [Source: (String)"{"endTime": "2022-01-13 23:57:58", "startTime": "2022-01-13 23:57:56", "numResults": 6, "numFailures": 0, "sampleResults": {"0": {"id": 0, "enabled": false, "resultsMap": {"tst": "FAIL", "tst2": "PASS"}, "containerId": null, "criteriaMap": {}}, "1": {"id": 1, "enabled": false, "resultsMap": {"tst": "FAIL", "tst2": "PASS"}, "containerId": null, "criteriaMap": {}}, "2": {"id": 2, "enabled": true, "resultsMap": {}, "containerId": null, "criteriaMap": {"ICCI_VE_OSW_B_Z01": "N_A", "ICCI_VE_OSW_B_Z02""[truncated 464 chars]; line: 1, column: 13] (through reference chain: filtec.test.TestRun["endTime"])
at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1991)
at com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:1219)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseDate(StdDeserializer.java:1261)
...
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4675)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3630)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3598)
at filtec.db.TestRunEntity.getData(TestRunEntity.java:79)
the calling method:
public TestRun getData() {
TestRun data = null;
try {
data = MAPPER.readValue(jsonDoc, TestRun.class);
} catch (JsonProcessingException e) {
ApplicationManager.logStackTrace(e);
}
return data;
}
my serializer:
public class JsonTimestampSerializer extends JsonSerializer<Timestamp> {
@Override
public void serialize(Timestamp value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s = sdf.format(value);
gen.writeString(s);
} catch (DateTimeParseException e) {
System.err.println(e);
gen.writeString("");
}
}
}
and my TestRun POJO fields:
public class TestRun {
//...
/** Internal state of a test run. */
enum State {
CREATED,
IN_PROGRESS,
COMPLETE
}
/** State of the test session. */
State state = State.CREATED;
/** The start time of the run. */
@JsonSerialize(using = JsonTimestampSerializer.class)
Timestamp startTime;
/** The end time of the test run. */
@JsonSerialize(using = JsonTimestampSerializer.class)
Timestamp endTime;
sdf.format(value)can't throwDateTimeParseException... have you confused serialization and de-serialization?DateTimeParserException, cannot occur here, but could occur in a deserializer.