class JSONUtils {

    public static JsonNode mergeNodesForGivenPaths(JsonNode newNode, JsonNode originalNode, List<String> filterPaths) throws IOException {
        Configuration configuration = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL,
                Option.SUPPRESS_EXCEPTIONS);
        ObjectMapper mapper = new ObjectMapper(new JsonFactory());

        JsonNode mergedNode = originalNode.deepCopy();
        DocumentContext mergedNodeDocumentContext = JsonPath.using(configuration).parse(mergedNode.toString());

        ArrayNode newArrayNode = (ArrayNode) newNode;

        for(int i = 0; i < filterPaths.size(); i++) {
            String path = filterPaths.get(i);
            if(mergedNodeDocumentContext.read(path) == null)
                continue;
            if(path.contains("*")) {
                ArrayNode values = (ArrayNode) newArrayNode.get(i);

                for(int j = 0; j < values.size(); j++) {
                    String absolutePath = path.replace("*", String.valueOf(j));
                    mergedNodeDocumentContext.set(absolutePath, values.get(j).textValue());
                }

            } else {
                mergedNodeDocumentContext.set(path, newArrayNode.get(i).textValue());
            }
        }

        return mapper.readTree(mergedNodeDocumentContext.jsonString());
    }

}