JacksonDSL { public static Representation JsonStream(final Iterable<String> stream){ return new Representation() { private final ObjectMapper mapper = new ObjectMapper(); @Override public void write(OutputStream out) { JsonGenerator generator=null; try{ JsonFactory jsonFactory = mapper.getFactory(); generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8); generator.writeStartArray(); for(String obj:stream){ generator.writeTree(mapper.readTree(obj)); } generator.writeEndArray(); }catch(Exception e){ throw new RuntimeException(e); }finally{ try{ generator.close(); }catch(Exception e){} } } @Override public String contentType() { return DSL.CONTENT_TYPE_JSON; } }; }  static RepresentationConverter convertRepresentation(Representation representation); static Representation JacksonJson(final Object object, final ObjectMapper jackson); static Representation JsonStream(final Iterable<String> stream); static Representation JacksonJson(final Object object);  }
@Test public void writesJsonRepresentationsOfStreamsOfStrings() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); List<String> strings = Arrays.asList("{\"message\":\"Hello\"}", "{\"message\":\"Goodbye\"}"); JacksonDSL.JsonStream(strings).write(outputStream); assertEquals(outputStream.toString(), "[{\"message\":\"Hello\"},{\"message\":\"Goodbye\"}]"); }