Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to format this using Jackson JSON?

 
Ong Vua
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic