JsonRecordCompactor extends RecordCompactor { @Override protected String compact(final String payload) { if (payload == null) { return null; } if (payload.trim().isEmpty()) { return EMPTY_STRING; } String dataSource = "[" + payload + "]"; return doCompactPayload(dataSource); }    }
@Test public void testCompactSimpleJsonRecord() { expectedPayload = "{\"name\":\"foo\",\"age\":30,\"married\":false}"; payload = "{" + LINE_SEPARATOR + " \"name\": \"foo\"," + LINE_SEPARATOR + " \"age\": 30," + LINE_SEPARATOR + " \"married\": false" + LINE_SEPARATOR + "}"; String compactRecord = jsonRecordCompactor.compact(payload); assertThat(compactRecord).isNotNull().isEqualTo(expectedPayload); }
@Test public void testCompactComplexJsonRecord() { expectedPayload = "{\"datasetid\":\"arbresalignementparis2010\",\"recordid\":\"0e6cfe03082224225c54690e5a700987ffb1310f\",\"fields\":{\"adresse\":\"AVENUE GAMBETTA\",\"hauteurenm\":0.0,\"espece\":\"Tilia tomentosa\",\"circonfere\":78.0,\"geom_x_y\":[48.8691944661,2.40210336054],\"dateplanta\":\"1971-02-27\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[2.40210336054,48.8691944661]},\"record_timestamp\":\"2014-09-11T14:39:16.131843\"}"; payload = "{" + LINE_SEPARATOR + " \"datasetid\": \"arbresalignementparis2010\"," + LINE_SEPARATOR + " \"recordid\": \"0e6cfe03082224225c54690e5a700987ffb1310f\"," + LINE_SEPARATOR + " \"fields\": {" + LINE_SEPARATOR + " \"adresse\": \"AVENUE GAMBETTA\"," + LINE_SEPARATOR + " \"hauteurenm\": 0.0," + LINE_SEPARATOR + " \"espece\": \"Tilia tomentosa\"," + LINE_SEPARATOR + " \"circonfere\": 78.0," + LINE_SEPARATOR + " \"geom_x_y\": [" + LINE_SEPARATOR + " 48.8691944661," + LINE_SEPARATOR + " 2.40210336054" + LINE_SEPARATOR + " ]," + LINE_SEPARATOR + " \"dateplanta\": \"1971-02-27\"" + LINE_SEPARATOR + " }," + LINE_SEPARATOR + " \"geometry\": {" + LINE_SEPARATOR + " \"type\": \"Point\"," + LINE_SEPARATOR + " \"coordinates\": [" + LINE_SEPARATOR + " 2.40210336054," + LINE_SEPARATOR + " 48.8691944661" + LINE_SEPARATOR + " ]" + LINE_SEPARATOR + " }," + LINE_SEPARATOR + " \"record_timestamp\": \"2014-09-11T14:39:16.131843\"" + LINE_SEPARATOR + "}"; String compactRecord = jsonRecordCompactor.compact(payload); assertThat(compactRecord).isNotNull().isEqualTo(expectedPayload); }