DecomposeObjectArrayBolt extends AbstractProcessingBolt { @Override protected void process(LogRecord record) { String arrayJson = record.getValue(arrayField); Gson gson = new Gson(); List list = gson.fromJson(arrayJson, List.class); List decomposeList = new ArrayList<>(); if(list != null) { for (Object object : list) { Map map = (Map) object; decomposeList.add(map.get(objectField)); } } String json = new Gson().toJson(decomposeList); record.setValue(destField, json); }  @Override void configure(Configuration conf); static final String ARRAY_FIELD; static final String OBJECT_FIELD; static final String DEST_FIELD; }
@Test public void testProcess(@Injectable LogRecord record) throws Exception { bolt.arrayField = "array-field"; bolt.objectField = "text"; bolt.destField = "dest-field"; new Expectations() {{ record.getValue(bolt.arrayField); result = "[{\"indices\":[10,23],\"text\":\"CecilTheLion\"},{\"indices\":[72,85],\"text\":\"RinglingBros\"},{\"indices\":[112,131],\"text\":\"JusticeForAllLions\"}]"; record.setValue(bolt.destField, "[\"CecilTheLion\",\"RinglingBros\",\"JusticeForAllLions\"]"); }}; bolt.process(record); }