I want to convert an Array into a Json Object like
String[] array = {"value1", "value2"};
into
{
"array": ["value1", "value2"]
}
I am using Spring (Jackson XML).
I tried:
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode jsonNode = objectMapper.createObjectNode();
String[] array = {"value1", "value2"};
jsonNode.put("array", Arrays.toString(array));
System.out.print(jsonNode.toString());
But the result is
{
"array":"[value1, value2]"
}
And not
{
"array":["value1", "value2"]
}
what I want to get.
Arrays.toStringand instead pass the array itself.