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 need a JsonNodeFactory:
final JsonNodeFactory factory = JsonNodeFactory.instance;
This class has methods to create ArrayNode
s, ObjectNode
s, IntNode
s, DecimalNode
s, TextNode
s and whatnot. ArrayNode
s and ObjectNode
s have convenience mutation methods for adding directly most JSON primitive (non container) values without having to go through the factory (well, internally, they reference this factory, that is why).
As to an ObjectMapper
, note that it is both a serializer (ObjectWriter
) and deserializer (ObjectReader
).