0

I want to write java string array into JSON array.

Array : ["abc","def","ghi","jkl","mno"]

One way is to loop over the array and add the elements one by one as below

JsonGenerator jsonGen = factory.createGenerator(output, JsonEncoding.UTF8);
jsonGen.writeArrayFieldStart("args");
for (String val : arr)  {
  jsonGen.writeString(val);
}
jsonGen.writeEndArray();

Is there any way to convert a string array into JSON array directly (i.e. without iterating over it)?

Lee Mac
  • 15,615
  • 6
  • 32
  • 80

0 Answers0