class JacksonUtils {

    static JsonNode filterJsonNodeForPath(JsonNode jsonNode, String filterPath) {
        ObjectMapper objectMapper = new ObjectMapper(new JsonFactory());

        if(filterPath == null)
            return jsonNode;
        else if(jsonNode == null)
            return null;

        String key = getFirstJsonKeyForPath(filterPath);
        JsonNode newNode = null;

        try {
            if (key.contains("*")) {                                                         //ArrayNode
                ArrayNode arrayNode = (ArrayNode) jsonNode;
                newNode = objectMapper.createArrayNode();
                for (JsonNode value : arrayNode) {
                    JsonNode filteredNode = filterJsonNodeForPath(value, getRemainingJsonKeyForPath(filterPath));
                    if(filteredNode != null && ! filteredNode.isNull())
                        ((ArrayNode) newNode).add(filteredNode);
                }
            } else {                                                                        //ObjectNode
                ObjectNode objectNode = (ObjectNode) jsonNode;
                newNode = objectMapper.createObjectNode();
                JsonNode value = objectNode.get(key);
                JsonNode filteredNode = filterJsonNodeForPath(value, getRemainingJsonKeyForPath(filterPath));
                if(filteredNode != null && ! filteredNode.isNull())
                    ((ObjectNode) newNode).set(key, filteredNode);
            }
        } catch (ClassCastException e) {
            log.error("Cannot find value for path : " + filterPath);
        }

        return newNode;
    }

}