title: write Java List to JSON Array via Jackson
body: <p>I am using Jackson for JSON serialization.  I am trying to convert a Java List (containing string values) to a JSON array.  I tried the following approaches (issues given below for each)</p>
  
  <p><strong>1.  write array elements using JsonGenerator's writeString</strong>  </p>
  
  <pre><code>final JsonGenerator generator = factory.createGenerator(output, JsonEncoding.UTF8);
    generator.writeStartArray();
          for (String arg: argsList) {
              generator.writeStartObject();
              log.info("arg value is {}", arg);
              generator.writeString(arg);
              generator.writeEndObject();
          }
          generator.writeEndArray();
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <pre><code>Can not write a string, expecting field name (context: Object)
  </code></pre>
  
  <p>I get the exception from "generator.writeString(arg)".  I cannot use writeStringField.  </p>
  
  <p><strong>object mapper</strong> </p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  mapper.writeValue(out, argsList);
              final byte[] argsBytes = out.toByteArray();
              generator.writeFieldName("args");
              generator.writeObjectField("args", argsBytes) 
  </code></pre>
  
  <p>This creates the array as a String and not an array within the JSON object (which is what I am trying to achieve).  Any suggestions would be welcome.</p>
  
  <p>End state (trying to achieve):</p>
  
  <pre><code>{
  "args":["abc","def","ghi","jkl","mno"]
  }
  </code></pre>