I'm trying to use modelmapper to map my Class with the incoming request.
It looks like Date is not able to auto convert in modelmapper.
Converter org.modelmapper.internal.converter.DateConverter@7595415b failed to convert java.lang.String to java.util.Date. Caused by: org.modelmapper.MappingException: ModelMapper mapping errors:
The above is the exception which is get.
So how to skip this Date field alone
Currently My code looks like,
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
MyClass obj=mapper.map(anotherObject,MyClass.class);
MyClass
public class MyClass {
int id;
Date updated_at;
}
anotherObject.toString
{id=6,updated_at=2018-02-23T03:01:12}
UPDATE 2
Apologies for the misguiding here.Actually, my anotherObject is not a class object. I'll explain my exact scenario below
My API response
{
"rows": 1,
"last": null,
"results": [
{
"id": "1",
"updated_at;": "2018-01-22T13:00:00",
},
{
"id": "2",
"updated_at;": "2018-01-22T13:00:00",
}
]
}
MysuperClass
public class MysuperClass {
int rows;
String last;
List<Object> results;
}
Getting the response body using rest template
ResponseEntity<MysuperClass > apiResponse = restTemplate.exchange(Url, HttpMethod.GET, entity, MysuperClass .class)
MysuperClass anotherObject=apiResponse.getBody();
Actual Class
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
for (int index = 0; index < anotherObject.getResults().size(); index++) {
MyClass obj=mapper.map(anotherObject.getResults().get(index),MyClass.class);
}