ottobackwards commented on a change in pull request #3414: NIFI-5900 Add a SplitLargeJson processor URL: https://github.com/apache/nifi/pull/3414#discussion_r281614774
########## File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SimpleJsonPath.java ########## @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.standard.util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** A <code>SimpleJsonPath</code> instance serves as a functional representation of a JSON Path string. An instance + * of this class can be used to determine whether a particular location in a JSON document is targeted by a particular + * JSON Path expression. It is a list of the fundamental elements of a JSON Path, as designated by its inner classes + * (<code>Element</code> and its subclasses). */ +public class SimpleJsonPath { + private final List<Element> path; + private final List<Element> altPath; + private Boolean hasWildcard; + + private SimpleJsonPath(List<Element> path) { + this.path = Collections.unmodifiableList(path); + this.altPath = null; + } + + private SimpleJsonPath(List<Element> path, List<Element> altPath) { + this.path = Collections.unmodifiableList(path); + this.altPath = Collections.unmodifiableList(altPath); + } + + /* Unfortunately, the "[*]" construct is ambiguous in the JSON Path specification. It could either + * match a range of array elements OR a range of object fields. For example, see the disjointEmbeddedStar + * unit tests. This ambiguity ends up muddying the code. Accounting for a possible "alternative path" (altPath) + * is probably the cleanest (though maybe not the most efficient) way to handle the oddity. */ + public static SimpleJsonPath of(String str) { Review comment: Could these inline regex's be replaced by static compiled patterns? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
