I am using Jackson ObjectMapper
to convert a Java Bean to a Map
.
However, it is not preserving the Date
object, rather it gets converted to Long
.
Here is the failing test case,
@Test
public void testObjectToMapDate() {
User user = new User();
user.setDob(new Date());
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = mapper.convertValue(user, Map.class);
assertTrue(map.get("dob") instanceof Date);
}
Is there a simple solution to this?