DDMFormInstanceRecordJSONWriter implements DDMFormInstanceRecordWriter { @Override public DDMFormInstanceRecordWriterResponse write( DDMFormInstanceRecordWriterRequest ddmFormInstanceRecordWriterRequest) throws Exception { List<Map<String, String>> ddmFormFieldsValueList = ddmFormInstanceRecordWriterRequest.getDDMFormFieldValues(); JSONArray jsonArray = jsonFactory.createJSONArray(); Stream<Map<String, String>> stream = ddmFormFieldsValueList.stream(); stream.map( this::createJSONObject ).forEach( jsonArray::put ); String json = jsonArray.toJSONString(); DDMFormInstanceRecordWriterResponse.Builder builder = DDMFormInstanceRecordWriterResponse.Builder.newBuilder( json.getBytes()); return builder.build(); }  @Override DDMFormInstanceRecordWriterResponse write(
			DDMFormInstanceRecordWriterRequest
				ddmFormInstanceRecordWriterRequest);  }
@Test public void testWrite() throws Exception { DDMFormInstanceRecordJSONWriter ddmFormInstanceRecordJSONWriter = new DDMFormInstanceRecordJSONWriter(); ddmFormInstanceRecordJSONWriter.jsonFactory = new JSONFactoryImpl(); List<Map<String, String>> ddmFormFieldValues = new ArrayList<Map<String, String>>() { { add( HashMapBuilder.put( "field1", "2" ).put( "field2", "false" ).put( "field3", "11.7" ).build()); add( HashMapBuilder.put( "field1", "1" ).put( "field2", "" ).put( "field3", "10" ).build()); } }; DDMFormInstanceRecordWriterRequest.Builder builder = DDMFormInstanceRecordWriterRequest.Builder.newBuilder( Collections.emptyMap(), ddmFormFieldValues); DDMFormInstanceRecordWriterResponse ddmFormInstanceRecordWriterResponse = ddmFormInstanceRecordJSONWriter.write(builder.build()); StringBundler sb = new StringBundler(3); sb.append("[{\"field1\":\"2\",\"field3\":\"11.7\",\"field2\":"); sb.append("\"false\"},{\"field1\":\"1\",\"field3\":\"10\",\"field2\":"); sb.append("\"\"}]"); String expectedJSON = sb.toString(); Assert.assertArrayEquals( expectedJSON.getBytes(), ddmFormInstanceRecordWriterResponse.getContent()); }