Package com.fasterxml.jackson.core
Class JsonLocation
java.lang.Object
com.fasterxml.jackson.core.JsonLocation
- All Implemented Interfaces:
Serializable
Object that encapsulates Location information used for reporting
parsing (or potentially generation) errors, as well as current location
within input streams.
NOTE: users should be careful if using equals(java.lang.Object)
implementation as
it may or may not compare underlying "content reference" for equality.
Instead if would make sense to explicitly implementing equality checks
using specific criteria caller desires.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final int
protected final ContentReference
Reference to input source; never null (but may be that ofContentReference.unknown()
).protected final int
protected String
Lazily constructed description for source; constructed if and whensourceDescription()
is called, retained.protected final long
protected final long
static final int
Deprecated.static final JsonLocation
Shared immutable "N/A location" that can be returned to indicate that no location information is available. -
Constructor Summary
ConstructorDescriptionJsonLocation
(ContentReference contentRef, long totalChars, int lineNr, int colNr) JsonLocation
(ContentReference contentRef, long totalBytes, long totalChars, int lineNr, int columnNr) JsonLocation
(Object srcRef, long totalChars, int lineNr, int columnNr) Deprecated.JsonLocation
(Object srcRef, long totalBytes, long totalChars, int lineNr, int columnNr) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected static ContentReference
Accessor for information about the original input source content is being read from.boolean
long
long
int
Access for getting column position of this location, if available.int
Access for getting line number of this location, if available.Deprecated.Since 2.13 UsecontentReference()
insteadint
hashCode()
Accessor for a brief summary of Location offsets (line number, column position, or byte offset, if available).Accessor for getting a textual description of source reference (Object returned bygetSourceRef()
), as included in description returned bytoString()
.toString()
-
Field Details
-
MAX_CONTENT_SNIPPET
Deprecated.Since 2.13 useErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH
instead- See Also:
-
NA
Shared immutable "N/A location" that can be returned to indicate that no location information is available.NOTE: before 2.9, Location was given as String "N/A"; with 2.9 it was removed so that source should be indicated as "UNKNOWN".
-
_totalBytes
protected final long _totalBytes -
_totalChars
protected final long _totalChars -
_lineNr
protected final int _lineNr -
_columnNr
protected final int _columnNr -
_contentReference
Reference to input source; never null (but may be that ofContentReference.unknown()
).- Since:
- 2.13 (before we have
_sourceRef
(Object-valued)
-
_sourceDescription
Lazily constructed description for source; constructed if and whensourceDescription()
is called, retained.- Since:
- 2.13
-
-
Constructor Details
-
JsonLocation
-
JsonLocation
public JsonLocation(ContentReference contentRef, long totalBytes, long totalChars, int lineNr, int columnNr) -
JsonLocation
Deprecated. -
JsonLocation
@Deprecated public JsonLocation(Object srcRef, long totalBytes, long totalChars, int lineNr, int columnNr) Deprecated.
-
-
Method Details
-
_wrap
-
contentReference
Accessor for information about the original input source content is being read from. Returned reference is nevernull
but may not contain useful information.NOTE: not getter, on purpose, to avoid inlusion if serialized using default Jackson serializer.
- Returns:
- Object with information about input source.
- Since:
- 2.13 (to replace
getSourceRef
)
-
getSourceRef
Deprecated.Since 2.13 UsecontentReference()
insteadReference to the original resource being read, if one available. For example, when a parser has been constructed by passing aFile
instance, this method would return that File. Will return null if no such reference is available, for example whenInputStream
was used to construct the parser instance.- Returns:
- Source reference this location was constructed with, if any;
null
if none
-
getLineNr
public int getLineNr()Access for getting line number of this location, if available. Note that line number is typically not available for binary formats.- Returns:
- Line number of the location (1-based), if available;
-1
if not.
-
getColumnNr
public int getColumnNr()Access for getting column position of this location, if available. Note that column position is typically not available for binary formats.- Returns:
- Column position of the location (1-based), if available;
-1
if not.
-
getCharOffset
public long getCharOffset()- Returns:
- Character offset within underlying stream, reader or writer,
if available;
-1
if not.
-
getByteOffset
public long getByteOffset()- Returns:
- Byte offset within underlying stream, reader or writer,
if available;
-1
if not.
-
sourceDescription
Accessor for getting a textual description of source reference (Object returned bygetSourceRef()
), as included in description returned bytoString()
.Note: implementation will simply call
ContentReference.buildSourceDescription()
)NOTE: not added as a "getter" to prevent it from getting serialized.
- Returns:
- Description of the source reference (see
getSourceRef()
- Since:
- 2.9
-
offsetDescription
Accessor for a brief summary of Location offsets (line number, column position, or byte offset, if available).- Returns:
- Description of available relevant location offsets; combination of line number and column position or byte offset
- Since:
- 2.13
-
appendOffsetDescription
-
hashCode
public int hashCode() -
equals
-
toString
-
ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH
instead