class JSONUtils {

    public static JsonNode merge(JsonNode newNode, JsonNode originalNode) {
        Iterator<String> fieldNames = originalNode.fieldNames();

        while (fieldNames.hasNext()) {

            String fieldName = fieldNames.next();
            JsonNode jsonNode = newNode.get(fieldName);

            if (jsonNode != null) {
                if (jsonNode.isObject()) {
                    merge(jsonNode, originalNode.get(fieldName));
                } else if (jsonNode.isArray()) {
                    for (int i = 0; i < jsonNode.size(); i++) {
                        merge(jsonNode.get(i), originalNode.get(fieldName).get(i));
                    }
                }
            } else {
                if (newNode instanceof ObjectNode) {
                    // Overwrite field
                    JsonNode value = originalNode.get(fieldName);

                    ((ObjectNode) newNode).set(fieldName, value);
                }
            }
        }

        return newNode;
    }

}