Package com.fasterxml.jackson.core
Class JsonLocation
- java.lang.Object
-
- com.fasterxml.jackson.core.JsonLocation
-
- All Implemented Interfaces:
java.io.Serializable
public class JsonLocation extends java.lang.Object implements java.io.SerializableObject 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_CONTENT_SNIPPETDeprecated.Since 2.13 useErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTHinsteadstatic JsonLocationNAShared immutable "N/A location" that can be returned to indicate that no location information is available.
-
Constructor Summary
Constructors Constructor Description JsonLocation(ContentReference contentRef, long totalChars, int lineNr, int colNr)JsonLocation(ContentReference contentRef, long totalBytes, long totalChars, int lineNr, int columnNr)JsonLocation(java.lang.Object srcRef, long totalChars, int lineNr, int columnNr)Deprecated.JsonLocation(java.lang.Object srcRef, long totalBytes, long totalChars, int lineNr, int columnNr)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.StringBuilderappendOffsetDescription(java.lang.StringBuilder sb)ContentReferencecontentReference()Accessor for information about the original input source content is being read from.booleanequals(java.lang.Object other)longgetByteOffset()longgetCharOffset()intgetColumnNr()Access for getting column offset of this location, if available.intgetLineNr()Access for getting line number of this location, if available.java.lang.ObjectgetSourceRef()Deprecated.Since 2.13 UsecontentReference()insteadinthashCode()java.lang.StringoffsetDescription()Accessor for a brief summary of Location offsets (line number, column position, or byte offset, if available).java.lang.StringsourceDescription()Accessor for getting a textual description of source reference (Object returned bygetSourceRef()), as included in description returned bytoString().java.lang.StringtoString()
-
-
-
Field Detail
-
MAX_CONTENT_SNIPPET
@Deprecated public static final int MAX_CONTENT_SNIPPET
Deprecated.Since 2.13 useErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTHinstead- See Also:
- Constant Field Values
-
NA
public static final JsonLocation 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".
-
-
Constructor Detail
-
JsonLocation
public JsonLocation(ContentReference contentRef, long totalChars, int lineNr, int colNr)
-
JsonLocation
public JsonLocation(ContentReference contentRef, long totalBytes, long totalChars, int lineNr, int columnNr)
-
JsonLocation
@Deprecated public JsonLocation(java.lang.Object srcRef, long totalChars, int lineNr, int columnNr)Deprecated.
-
JsonLocation
@Deprecated public JsonLocation(java.lang.Object srcRef, long totalBytes, long totalChars, int lineNr, int columnNr)Deprecated.
-
-
Method Detail
-
contentReference
public ContentReference contentReference()
Accessor for information about the original input source content is being read from. Returned reference is nevernullbut 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 public java.lang.Object 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 aFileinstance, this method would return that File. Will return null if no such reference is available, for example whenInputStreamwas used to construct the parser instance.- Returns:
- Source reference this location was constructed with, if any;
nullif 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;
-1if not.
-
getColumnNr
public int getColumnNr()
Access for getting column offset of this location, if available. Note that column position is typically not available for binary formats. Note: this returns an offset that is in units of input, so forbyte-based input sources (likeInputStream) this does not take into account multi-byte characters: one logical character can be 1, 2 or 3 bytes long. To calculate column position in characters eitherchar-based input source (likeReader) needs to be used, or content needs to be explicitly decoded.- Returns:
- Column offset of the location (1-based), if available;
-1if not.
-
getCharOffset
public long getCharOffset()
- Returns:
- Character offset within underlying stream, reader or writer,
if available;
-1if not.
-
getByteOffset
public long getByteOffset()
- Returns:
- Byte offset within underlying stream, reader or writer,
if available;
-1if not.
-
sourceDescription
public java.lang.String 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
public java.lang.String 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
public java.lang.StringBuilder appendOffsetDescription(java.lang.StringBuilder sb)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-