I'm looking for a way to directly convert some POJO to a Jackson TreeModel. I know that a translation from POJO-to-JSON-String exists, and TreeModel-to-JSON-String is supported — hovewer I am looking for a POJO-to-TreeModel translation. Is there a way?
The use-case is as follows:
This, ideally, involves two serialization steps. However, in my workaround, I am currently using three — which you can see here:
map = // a map of pojos with jackson annotations
//pojo >> JSON
StringWriter w = new StringWriter();
objectmapper.writeValue(new JsonFactory().createJsonGenerator(w), map);
String json = w.toString();
w.close();
//JSON >> Treemodel
JsonNode tree = GenericJcrDTO.mapper.readTree(json);
//filter tree here
//treemodel >>JSON
StringWriter w = new StringWriter();
GenericJcrDTO.mapper.writeValue(new JsonFactory().createJsonGenerator(w), tree);
json = w.toString();
w.close();
Anyone?
to answer my own question:
JsonNode node = objectMapper.valueToTree(map);