Class PropertyPath
"person.addresses[1].city".
Parses bean property paths for property access: it decides whether a given string is a well-formed property path (see grammar) and where each path segment begins and ends. The canonical form is used for policy matching and error reporting. The structured segment list is used for property navigation within beans.
The grammar is:
PropertyPath := Segment ('.' Segment)*
Segment := Name Index* -- Name may be empty only if at least one Index follows
Name := char* excluding '.', '[', ']'
Index := '[' Key ']'
Key := QuotedKey | RawKey
QuotedKey := "'" [^']* "'" | '"' [^"]* '"'
RawKey := char* excluding quote characters, with balanced '[' / ']' nesting
Invalid property paths are rejected with InvalidPropertyPathException.
- Since:
- 7.1
- Author:
- Brian Clozel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOptions to customize the parsing forPropertyPath.static final recordA dot-separated segment of a property path. -
Method Summary
Modifier and TypeMethodDescriptionReturn the canonical string form of this path.static Stringpath's canonical form, orpathitself if it is not a well-formed property path (including anullpath, for which this returns an empty string).booleaninthashCode()static PropertyPathParse the given property path.static PropertyPathparse(String path, PropertyPath.Options options) Parse the given property path, rejecting it if it exceeds the givenoptions.segments()Return the segments of this path, in order, as an unmodifiable list.subPath(int fromIndex) Return the sub-path made up of this path's segments from the given index to the end, such as the"country.name"sub-path of"address.country.name"from index 1.toString()
-
Method Details
-
parse
Parse the given property path.- Parameters:
path- the property path to parse; an empty string is a valid path with no segments- Returns:
- the parsed property path
- Throws:
InvalidPropertyPathException- if the given path is not a well-formed property path
-
parse
public static PropertyPath parse(String path, PropertyPath.Options options) throws InvalidPropertyPathException Parse the given property path, rejecting it if it exceeds the givenoptions.- Parameters:
path- the property path to parse; an empty string is a valid path with no segmentsoptions- the parsing options to apply- Returns:
- the parsed property path
- Throws:
InvalidPropertyPathException- if the given path is not a well-formed property path, or if it exceeds the given options
-
canonicalNameOrOriginal
path's canonical form, orpathitself if it is not a well-formed property path (including anullpath, for which this returns an empty string).A convenience for callers with nothing better to fall back to than the original string, such as canonicalizing a user-supplied field name for display, comparison, or configuration matching, as opposed to
parse(String)itself, whose non-throwing behavior would be the wrong default for a caller that is about to navigate an object graph.- Parameters:
path- the property path to canonicalize, possiblynull- Returns:
- the canonical form of
path, orpathunchanged (or an empty string, ifpathisnull) if it is not a well-formed property path - Since:
- 7.1
-
canonicalName
Return the canonical string form of this path.Unnecessary surrounding quotes are removed from keys:
map['key'].name→map[key].name. -
segments
Return the segments of this path, in order, as an unmodifiable list. -
subPath
Return the sub-path made up of this path's segments from the given index to the end, such as the"country.name"sub-path of"address.country.name"from index 1.- Parameters:
fromIndex- the index of the first segment to include (inclusive)- Returns:
- the sub-path starting at
fromIndex - Throws:
IndexOutOfBoundsException- iffromIndexis negativeIllegalArgumentException- iffromIndexis greater thansegments().size()
-
equals
-
hashCode
-
toString
-