Using Spring Boot 1.4.4.RELEASE, have saved a RequestBody
to MongoDB as below:
{
"startTime" : NumberLong("1483542955570"),
"startDate" : ISODate("2017-01-04T15:15:55.570Z"),
"endTime" : NumberLong("1483542955570"),
"endDate" : ISODate("2017-01-04T15:15:55.570Z")
}
While mapping this back to a Java POJO, I am trying the below code.
public <T> T getPOJOFromMongoDocument(Document resourceDocument, Class<T> clazz) {
String serialize = JSON.serialize(resourceDocument);
return objectMapper.readValue(serialize,
clazz);
}
serialize has the date fields returned as following
"startDate" : { "$date" : "2017-01-04T15:15:55.570Z"}
Due to $date
, Jackson ObjectMapper
returns the below exception during parsing:
java.lang.RuntimeException: Error parsing mongoDoc to Pojo : errorMessage : {Can not deserialize instance of java.util.Date out of START_OBJECT token at [Source: {
"startTime": 1483542955570,
"startDate": {
"$date": "2017-01-04T15:15:55.570Z"
},
"endTime": 1483542955570,
"endDate": {
"$date": "2017-01-04T15:15:55.570Z"
}}; line: 1, column: 381] (through reference chain: com.gofynd.engine.mongo.models.RuleWithDataVO["validity"]->com.gofynd.engine.mongo.models.ValidityVO["startDate"])}
Is there way to solve this without using an ODM?