How can I create a json array like the example below using jackson.
I tried using ObjectMapper, but this does not seem correct.
try (Director
You can do this without creating POJO and converting it into JSON. I assume your data in the Record object.
JsonNode rootNode = mapper.createObjectNode();
ArrayNode childNodes = mapper.createArrayNode();
for (Record record : records) {
JsonNode element = mapper.createObjectNode();
((ObjectNode) element).put("mime": record.getDirectory());
//fill rest of fields which are needed similar to this.
//Also here record.getDirectory() method will should return "directory"
//according to your json file.
childNodes.add(element);
}
((ObjectNode) rootNode).put("files", childNodes);