Source:
private String constructJsonForDefaultMapping(Object eventObj) { StringBuilder sb = new StringBuilder(); int numberOfOuterObjects = 0; if (enclosingElement != null) { String[] nodeNames = enclosingElement.split("\\."); if (DEFAULT_ENCLOSING_ELEMENT.equals(nodeNames[0])) { numberOfOuterObjects = nodeNames.length - 1; } else { numberOfOuterObjects = nodeNames.length; } for (String nodeName : nodeNames) { if (!DEFAULT_ENCLOSING_ELEMENT.equals(nodeName)) { sb.append(JSON_EVENT_START_SYMBOL).append("\"").append(nodeName).append("\"") .append(JSON_KEYVALUE_SEPERATOR); } } if (eventObj.getClass() == Event.class) { Event event = (Event) eventObj; JsonObject jsonEvent = constructSingleEventForDefaultMapping(doPartialProcessing(event)); sb.append(jsonEvent); } else if (eventObj.getClass() == Event[].class) { JsonArray eventArray = new JsonArray(); for (Event event : (Event[]) eventObj) { eventArray.add(constructSingleEventForDefaultMapping(doPartialProcessing(event))); } sb.append(eventArray.toString()); } else { log.error("Invalid object type. " + eventObj.toString() + " cannot be converted to an event or event array. Hence dropping message."); return null; } for (int i = 0; i < numberOfOuterObjects; i++) { sb.append(JSON_EVENT_END_SYMBOL); } return sb.toString(); } else { if (eventObj.getClass() == Event.class) { Event event = (Event) eventObj; JsonObject jsonEvent = constructSingleEventForDefaultMapping(doPartialProcessing(event)); return jsonEvent.toString(); } else if (eventObj.getClass() == Event[].class) { JsonArray eventArray = new JsonArray(); for (Event event : (Event[]) eventObj) { eventArray.add(constructSingleEventForDefaultMapping(doPartialProcessing(event))); } return (eventArray.toString()); } else { log.error("Invalid object type. " + eventObj.toString() + " cannot be converted to an event or event array."); return null; } } }

Target:
private String constructJsonForDefaultMapping(Object eventObj) { StringBuilder sb = new StringBuilder(); int numberOfOuterObjects; if (enclosingElement != null) { String[] nodeNames = enclosingElement.split("\\."); if (DEFAULT_ENCLOSING_ELEMENT.equals(nodeNames[0])) { numberOfOuterObjects = nodeNames.length - 1; } else { numberOfOuterObjects = nodeNames.length; } for (String nodeName : nodeNames) { if (!DEFAULT_ENCLOSING_ELEMENT.equals(nodeName)) { sb.append(JSON_EVENT_START_SYMBOL).append("\"").append(nodeName).append("\"") .append(JSON_KEYVALUE_SEPERATOR); } } if (eventObj instanceof Event) { Event event = (Event) eventObj; JsonObject jsonEvent = constructSingleEventForDefaultMapping(doPartialProcessing(event)); sb.append(jsonEvent); } else if (eventObj instanceof Event[]) { JsonArray eventArray = new JsonArray(); for (Event event : (Event[]) eventObj) { eventArray.add(constructSingleEventForDefaultMapping(doPartialProcessing(event))); } sb.append(eventArray.toString()); } else { log.error("Invalid object type. " + eventObj.toString() + " cannot be converted to an event or event array. Hence dropping message."); return null; } for (int i = 0; i < numberOfOuterObjects; i++) { sb.append(JSON_EVENT_END_SYMBOL); } return sb.toString(); } else { if (eventObj instanceof Event) { Event event = (Event) eventObj; JsonObject jsonEvent = constructSingleEventForDefaultMapping(doPartialProcessing(event)); return jsonEvent.toString(); } else if (eventObj instanceof Event[]) { JsonArray eventArray = new JsonArray(); for (Event event : (Event[]) eventObj) { eventArray.add(constructSingleEventForDefaultMapping(doPartialProcessing(event))); } return (eventArray.toString()); } else { log.error("Invalid object type. " + eventObj.toString() + " cannot be converted to an event or event array."); return null; } } }