Package org.json
Class ParserConfiguration
java.lang.Object
org.json.ParserConfiguration
- Direct Known Subclasses:
JSONMLParserConfiguration,JSONParserConfiguration,XMLParserConfiguration
Configuration base object for parsers. The configuration is immutable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default max number lengthstatic final intThe default maximum nesting depth when parsing a document.protected booleanSpecifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string).protected intThe maximum nesting depth when parsing an object.protected intThe max number of chars for any number.static final intUsed to indicate there's no defined limit to the maximum nesting depth when parsing a document.static final intUsed to indicate there's no defined limit to the maximum number length -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a new ParserConfiguration with default settings.protectedParserConfiguration(boolean keepStrings, int maxNestingDepth) Deprecated.Use the with*() methods instead -
Method Summary
Modifier and TypeMethodDescriptionprotected ParserConfigurationclone()Provides a new instance of the same configuration.intThe maximum nesting depth that the parser will descend before throwing an exception when parsing an object (e.g.intThe maximum number length that the parser will allowbooleanWhen 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>
TwithKeepStrings(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>
TwithMaxNestingDepth(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>
TwithMaxNumberLength(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
-
Field Details
-
UNDEFINED_MAXIMUM_NESTING_DEPTH
public static final int UNDEFINED_MAXIMUM_NESTING_DEPTHUsed to indicate there's no defined limit to the maximum nesting depth when parsing a document.- See Also:
-
UNDEFINED_MAXIMUM_NUMBER_LENGTH
public static final int UNDEFINED_MAXIMUM_NUMBER_LENGTHUsed to indicate there's no defined limit to the maximum number length- See Also:
-
DEFAULT_MAXIMUM_NESTING_DEPTH
public static final int DEFAULT_MAXIMUM_NESTING_DEPTHThe default maximum nesting depth when parsing a document.- See Also:
-
DEFAULT_MAX_NUMBER_LENGTH
public static final int DEFAULT_MAX_NUMBER_LENGTHThe default max number length- See Also:
-
keepStrings
protected boolean keepStringsSpecifies 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 maxNestingDepthThe maximum nesting depth when parsing an object. -
maxNumberLength
protected int maxNumberLengthThe max number of chars for any number. Exceeding this limit will cause the value to be converted to a string
-
-
Constructor Details
-
ParserConfiguration
public ParserConfiguration()Constructs a new ParserConfiguration with default settings. -
ParserConfiguration
Deprecated.Use the with*() methods insteadConstructs 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 Details
-
clone
Provides a new instance of the same configuration. -
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
keepStringsconfiguration value.
-
withKeepStrings
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 thekeepStringsconfiguration 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
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
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.
-