Class JSONParserErrorHandlingOptions


  • public class JSONParserErrorHandlingOptions
    extends Object
    A data structure to hold options to change the behavior of the JSON parser when it encounters a questionable JSON token and switches to change the error message format JSONParserException. See JSONParserException for more details about how the error messages are formatted.

    Instances of this class are immutable.

    This class follows Builder Pattern. To make an instance of this class, use the code snippet something like below:

     JSONLexerErrorErrorHandlingOptions opts =
         JSONLexerErrorMessageConfiguration.builder()
             .showURI(false)
             .showLineAndColumnNumber(true)
             .showErrorLine(false)
             .failOnDuplicateKey(false)
             .failOnTooBigNumber(false)
             .warningStream(System.err)
             .build();
     

    The invocation of methods between builder() and JSONParserErrorHandlingOptions.Builder.build() are optional. If you want to use the default configuration, just do not call them.

    The default value may change in the future, so do not rely on them if you really need a specific error handling behavior.

    • Method Detail

      • showURI

        public boolean showURI()
        Returns whether an error message should show URI of a JSON text source instead of a short name.
        Returns:
        represents whether an error message should show URI
      • showLineAndColumnNumber

        public boolean showLineAndColumnNumber()
        Returns whether an error message should show line and column number instead of character position within a JSON text source
        Returns:
        represents whether an error message should show line and column number instead of character position within a JSON text source
      • showErrorLine

        public boolean showErrorLine()
        Returns whether an error message should show actual JSON text line where the problme happened with markers to indicate which character(s) have the problem.
        Returns:
        represents whether an error message should show actual JSON text line where the problem happened with markers to indicate which character(s) have the problem.
      • failOnDuplicateKey

        public boolean failOnDuplicateKey()
        Returns whether the parse should throw an exception when it encounters duplicated keys in one JSON object.
        Returns:
        whether the parse should throw an exception when it encounters duplicated keys
      • failOnTooBigNumber

        public boolean failOnTooBigNumber()
        Returns whether the parse should throw an exception when there is a number that is not in the range [-(2^53)+1, 2^53 - 1].

        As indicated by RFC 8259 - 6. Numbers, some JSON parser implementations may internally covert a number to a double precision floating point value regardless whether it is an integer or not. To maximize the interoperability, it is a good idea to keep the number within this range so that not information loss occurs for integer values. This option enforces that policy to the users.

        Returns:
        whether the parse should throw an exception when there is a number that is not in the range [-(2^53)+1, 2^53-1].
      • warningStream

        @Nullable
        public @Nullable PrintStream warningStream()
        Returns the stream where warnings should be printed.
        Returns:
        the stream where warnings should be printed. Null to print warnings nowhere.