Package com.alibaba.fastjson2
Class JSONWriter.Path
java.lang.Object
com.alibaba.fastjson2.JSONWriter.Path
- Enclosing class:
JSONWriter
Path represents a JSON pointer path used for reference detection during serialization.
It tracks the location of objects within a JSON structure to detect circular references
and avoid infinite loops during serialization.
The Path class is used internally by JSONWriter to manage object references and generate JSON Pointer strings as defined in RFC 6901. Paths are hierarchical, with each Path instance containing a reference to its parent Path, forming a tree structure that mirrors the JSON structure being serialized.
Path instances are immutable once created and are used in reference detection to determine if an object has already been serialized at another location in the JSON structure.
Example paths:
- ROOT path: "$"
- Property path: \"$.name\"
- Array element path: \"$.items[0]\"
- Nested path: \"$.person.address.street\"
- Since:
- 2.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JSONWriter.PathThe manager reference path instance, used for special reference handling.final JSONWriter.PathThe parent path of this path segment, or null if this is the root path.static final JSONWriter.PathThe root path instance, representing the top level of the JSON structure. -
Constructor Summary
ConstructorsConstructorDescriptionPath(JSONWriter.Path parent, int index) Creates a new Path instance representing an array index.Path(JSONWriter.Path parent, String name) Creates a new Path instance representing a named property. -
Method Summary
-
Field Details
-
ROOT
The root path instance, representing the top level of the JSON structure. This is the starting point for all path calculations. -
MANGER_REFERNCE
The manager reference path instance, used for special reference handling. -
parent
The parent path of this path segment, or null if this is the root path.
-
-
Constructor Details
-
Path
Creates a new Path instance representing a named property.- Parameters:
parent- the parent path, or null for the root pathname- the property name for this path segment
-
Path
Creates a new Path instance representing an array index.- Parameters:
parent- the parent path, or null for the root pathindex- the array index for this path segment
-
-
Method Details
-
equals
Compares this Path with another object for equality. Two Path instances are considered equal if they have the same parent, name, and index. -
hashCode
public int hashCode()Returns a hash code value for this Path. -
toString
Returns a string representation of this Path in JSON Pointer format.
-