aspose file tools*
The moose likes Other Open Source Projects and the fly likes How to format this using Jackson JSON? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to format this using Jackson JSON?" Watch "How to format this using Jackson JSON?" New topic
Author

How to format this using Jackson JSON?

Ong Vua
Ranch Hand

Joined: Jan 24, 2008
Posts: 59
This is the desired output

{"node":{"type":"community","field_incentives":{"und":[{"value":"fun"},{"value":"nice"}]},"field_email":{"und":[{"value":"some@one.com"}]}}}

Here's my code.

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonFactory f = new JsonFactory();
JsonGenerator g = f.createJsonGenerator(outputStream);
g.writeStartObject();
g.writeObjectFieldStart("node");
g.writeStringField("type", "community");
g.writeObjectFieldStart("field_incentives");
g.writeFieldName("und");
g.writeStartArray();

???I don't know how to make [{"value":"fun"},{"value":"nice"}]
g.writeEndArray();
g.writeObjectFieldStart("field_email");
g.writeFieldName("und");
g.writeStartArray();

???
g.writeEndArray();
g.writeEndObject();
g.close();

Here's the output

{"node":{"type":"community","title","field_incentives":{"und":[],"field_email":{"und":[]}}}}

Thanks

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to format this using Jackson JSON?