Package org.json

Class ParserConfiguration

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_MAX_NUMBER_LENGTH
      The default max number length
      static int DEFAULT_MAXIMUM_NESTING_DEPTH
      The default maximum nesting depth when parsing a document.
      protected boolean keepStrings
      Specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string).
      protected int maxNestingDepth
      The maximum nesting depth when parsing an object.
      protected int maxNumberLength
      The max number of chars for any number.
      static int UNDEFINED_MAXIMUM_NESTING_DEPTH
      Used to indicate there's no defined limit to the maximum nesting depth when parsing a document.
      static int UNDEFINED_MAXIMUM_NUMBER_LENGTH
      Used to indicate there's no defined limit to the maximum number length
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        ParserConfiguration()
      Constructs a new ParserConfiguration with default settings.
      protected ParserConfiguration​(boolean keepStrings, int maxNestingDepth)
      Deprecated.
      Use the with*() methods instead
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected ParserConfiguration clone()
      Provides a new instance of the same configuration.
      int getMaxNestingDepth()
      The maximum nesting depth that the parser will descend before throwing an exception when parsing an object (e.g.
      int getMaxNumberLength()
      The maximum number length that the parser will allow
      boolean isKeepStrings()
      When parsing the XML into JSONML, specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string).
      <T extends ParserConfiguration>
      T
      withKeepStrings​(boolean newVal)
      When parsing the XML into JSONML, specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string)
      <T extends ParserConfiguration>
      T
      withMaxNestingDepth​(int maxNestingDepth)
      Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing an object (e.g.
      <T extends ParserConfiguration>
      T
      withMaxNumberLength​(int maxNumberLength)
      Defines the maximum number length that the parser will allow Using any negative value as a parameter is equivalent to setting no limit to the length which means any size number is allowed
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UNDEFINED_MAXIMUM_NESTING_DEPTH

        public static final int UNDEFINED_MAXIMUM_NESTING_DEPTH
        Used to indicate there's no defined limit to the maximum nesting depth when parsing a document.
        See Also:
        Constant Field Values
      • UNDEFINED_MAXIMUM_NUMBER_LENGTH

        public static final int UNDEFINED_MAXIMUM_NUMBER_LENGTH
        Used to indicate there's no defined limit to the maximum number length
        See Also:
        Constant Field Values
      • DEFAULT_MAXIMUM_NESTING_DEPTH

        public static final int DEFAULT_MAXIMUM_NESTING_DEPTH
        The default maximum nesting depth when parsing a document.
        See Also:
        Constant Field Values
      • DEFAULT_MAX_NUMBER_LENGTH

        public static final int DEFAULT_MAX_NUMBER_LENGTH
        The default max number length
        See Also:
        Constant Field Values
      • keepStrings

        protected boolean keepStrings
        Specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string).
      • maxNestingDepth

        protected int maxNestingDepth
        The maximum nesting depth when parsing an object.
      • maxNumberLength

        protected int maxNumberLength
        The max number of chars for any number. Exceeding this limit will cause the value to be converted to a string
    • Constructor Detail

      • ParserConfiguration

        public ParserConfiguration()
        Constructs a new ParserConfiguration with default settings.
      • ParserConfiguration

        @Deprecated
        protected ParserConfiguration​(boolean keepStrings,
                                      int maxNestingDepth)
        Deprecated.
        Use the with*() methods instead
        Constructs a new ParserConfiguration with the specified settings. Use the with* methods instead of calling this ctor.
        Parameters:
        keepStrings - A boolean indicating whether to preserve strings during parsing.
        maxNestingDepth - An integer representing the maximum allowed nesting depth.
    • Method Detail

      • clone

        protected ParserConfiguration clone()
        Provides a new instance of the same configuration.
        Overrides:
        clone in class java.lang.Object
      • isKeepStrings

        public boolean isKeepStrings()
        When parsing the XML into JSONML, specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string).
        Returns:
        The keepStrings configuration value.
      • withKeepStrings

        public <T extends ParserConfiguration> T withKeepStrings​(boolean newVal)
        When parsing the XML into JSONML, specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string)
        Type Parameters:
        T - the type of the configuration object
        Parameters:
        newVal - new value to use for the keepStrings configuration option.
        Returns:
        The existing configuration will not be modified. A new configuration is returned.
      • getMaxNestingDepth

        public int getMaxNestingDepth()
        The maximum nesting depth that the parser will descend before throwing an exception when parsing an object (e.g. Map, Collection) into JSON-related objects.
        Returns:
        the maximum nesting depth set for this configuration
      • withMaxNestingDepth

        public <T extends ParserConfiguration> T withMaxNestingDepth​(int maxNestingDepth)
        Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing an object (e.g. Map, Collection) into JSON-related objects. The default max nesting depth is 512, which means the parser will throw a JsonException if the maximum depth is reached. Using any negative value as a parameter is equivalent to setting no limit to the nesting depth, which means the parses will go as deep as the maximum call stack size allows.
        Type Parameters:
        T - the type of the configuration object
        Parameters:
        maxNestingDepth - the maximum nesting depth allowed to the XML parser
        Returns:
        The existing configuration will not be modified. A new configuration is returned.
      • getMaxNumberLength

        public int getMaxNumberLength()
        The maximum number length that the parser will allow
        Returns:
        the maximum number lengtj set for this configuration
      • withMaxNumberLength

        public <T extends ParserConfiguration> T withMaxNumberLength​(int maxNumberLength)
        Defines the maximum number length that the parser will allow Using any negative value as a parameter is equivalent to setting no limit to the length which means any size number is allowed
        Type Parameters:
        T - the type of the configuration object
        Parameters:
        maxNumberLength - the maximum number length allowed
        Returns:
        The existing configuration will not be modified. A new configuration is returned.