Is it possible to serialize Java objects to lists and maps with Jackson library directly? I mean not to String
, not to byte[]
, but to java.util.Map
and java.util.List
.
This might be helpful when filtering out unnecessary fields dynamically.
I can do it in two steps, by first converting to String
.
ObjectMapper mapper = new ObjectMapper()
DTO dto = new DTO();
DTO[] dtos = {dto};
mapper.readValue(mapper.writeValueAsString(dto), Object.class); // Map
mapper.readValue(mapper.writeValueAsString(dtos), Object.class); // List