JsonParseException
Date: 2016-12-03

com.fasterxml.jackson.core

## Class JsonParseException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.io.IOException
      - - com.fasterxml.jackson.core.JsonProcessingException
        - - com.fasterxml.jackson.core.JsonParseException

- All Implemented Interfaces:
    java.io.Serializable
  Direct Known Subclasses:
    JsonEOFException

      public class JsonParseException
      extends JsonProcessingException

  Exception type for parsing problems, used when non-well-formed content (content that does not conform to JSON syntax as per specification) is encountered.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected JsonParser` | `_processor`
    `protected RequestPayload` | `_requestPayload` Optional payload that can be assigned to pass along for error reporting or handling purposes.

    - ### Fields inherited from class com.fasterxml.jackson.core.JsonProcessingException

      `_location`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonParseException(JsonParser p, java.lang.String msg)` Constructor that uses current parsing location as location, and sets processor (accessible via `getProcessor()`) to specified parser.
    `JsonParseException(JsonParser p, java.lang.String msg, JsonLocation loc)`
    `JsonParseException(JsonParser p, java.lang.String msg, JsonLocation loc, java.lang.Throwable root)`
    `JsonParseException(JsonParser p, java.lang.String msg, java.lang.Throwable root)`
    `JsonParseException(java.lang.String msg, JsonLocation loc)` Deprecated.
    `JsonParseException(java.lang.String msg, JsonLocation loc, java.lang.Throwable root)` Deprecated.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getMessage()` Overriding the getMessage() to include the request body
    `JsonParser` | `getProcessor()` Method that allows accessing underlying processor that triggered this exception; typically either `JsonParser` or `JsonGenerator` for exceptions that originate from streaming API.
    `RequestPayload` | `getRequestPayload()` Method that may be called to find payload that was being parsed, if one was specified for parser that threw this Exception.
    `java.lang.String` | `getRequestPayloadAsString()` The method returns the String representation of the request payload if one was specified for parser that threw this Exception.
    `JsonParseException` | `withParser(JsonParser p)` Fluent method that may be used to assign originating `JsonParser`, to be accessed using `getProcessor()`.
    `JsonParseException` | `withRequestPayload(RequestPayload p)` Fluent method that may be used to assign payload to this exception, to let recipient access it for diagnostics purposes.

    - ### Methods inherited from class com.fasterxml.jackson.core.JsonProcessingException

      `getLocation, getMessageSuffix, getOriginalMessage, toString`

    - ### Methods inherited from class java.lang.Throwable

      `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _processor

          protected transient JsonParser _processor

    - #### _requestPayload

          protected RequestPayload _requestPayload

      Optional payload that can be assigned to pass along for error reporting or handling purposes. Core streaming parser implementations DO NOT initialize this; it is up to using applications and frameworks to populate it.
      Since:
        2.8

  - ### Constructor Detail

    - #### JsonParseException

          @Deprecated
          public JsonParseException(java.lang.String msg,
                                       JsonLocation loc)

      Deprecated.

    - #### JsonParseException

          @Deprecated
          public JsonParseException(java.lang.String msg,
                                       JsonLocation loc,
                                       java.lang.Throwable root)

      Deprecated.

    - #### JsonParseException

          public JsonParseException(JsonParser p,
                            java.lang.String msg)

      Constructor that uses current parsing location as location, and sets processor (accessible via `getProcessor()`) to specified parser.
      Since:
        2.7

    - #### JsonParseException

          public JsonParseException(JsonParser p,
                            java.lang.String msg,
                            java.lang.Throwable root)

      Since:
        2.7

    - #### JsonParseException

          public JsonParseException(JsonParser p,
                            java.lang.String msg,
                            JsonLocation loc)

      Since:
        2.7

    - #### JsonParseException

          public JsonParseException(JsonParser p,
                            java.lang.String msg,
                            JsonLocation loc,
                            java.lang.Throwable root)

      Since:
        2.7

  - ### Method Detail

    - #### withParser

          public JsonParseException withParser(JsonParser p)

      Fluent method that may be used to assign originating `JsonParser`, to be accessed using `getProcessor()`.

      NOTE: `this` instance is modified and no new instance is constructed.

      Since:
        2.7

    - #### withRequestPayload

          public JsonParseException withRequestPayload(RequestPayload p)

      Fluent method that may be used to assign payload to this exception, to let recipient access it for diagnostics purposes.

      NOTE: `this` instance is modified and no new instance is constructed.

      Since:
        2.8

    - #### getProcessor

          public JsonParser getProcessor()

      Description copied from class: `JsonProcessingException`
      Method that allows accessing underlying processor that triggered this exception; typically either `JsonParser` or `JsonGenerator` for exceptions that originate from streaming API. Note that it is possible that `null` may be returned if code throwing exception either has no access to processor; or has not been retrofitted to set it; this means that caller needs to take care to check for nulls. Subtypes override this method with co-variant return type, for more type-safe access.
      Overrides:
        `getProcessor` in class `JsonProcessingException`
      Returns:
        Originating processor, if available; null if not.

    - #### getRequestPayload

          public RequestPayload getRequestPayload()

      Method that may be called to find payload that was being parsed, if one was specified for parser that threw this Exception.
      Returns:
        request body, if payload was specified; `null` otherwise
      Since:
        2.8

    - #### getRequestPayloadAsString

          public java.lang.String getRequestPayloadAsString()

      The method returns the String representation of the request payload if one was specified for parser that threw this Exception.
      Returns:
        request body as String, if payload was specified; `null` otherwise
      Since:
        2.8

    - #### getMessage

          public java.lang.String getMessage()

      Overriding the getMessage() to include the request body
      Overrides:
        `getMessage` in class `JsonProcessingException`