Package org.json
Class JSONParserConfiguration
java.lang.Object
org.json.ParserConfiguration
org.json.JSONParserConfiguration
Configuration object for the JSON parser. The configuration is immutable.
-
Field Summary
Fields inherited from class org.json.ParserConfiguration
DEFAULT_MAX_NUMBER_LENGTH, DEFAULT_MAXIMUM_NESTING_DEPTH, keepStrings, maxNestingDepth, maxNumberLength, UNDEFINED_MAXIMUM_NESTING_DEPTH, UNDEFINED_MAXIMUM_NUMBER_LENGTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected JSONParserConfigurationclone()Provides a new instance of the same configuration.booleanThe parser's behavior when meeting duplicate keys, controls whether the parser should overwrite duplicate keys or not.booleanThe parser throws an Exception when strict mode is true and tries to parse invalid JSON characters.booleanThe parser's behavior when meeting a null value in a java map, controls whether the parser should write a JSON entry with a null value (isUseNativeNulls() == true) or ignore that map entry (isUseNativeNulls() == false).withMaxNestingDepth(int maxNestingDepth) Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing a map into JSONObject or parsing aCollectioninstance into JSONArray.withOverwriteDuplicateKey(boolean overwriteDuplicateKey) Controls the parser's behavior when meeting duplicate keys.Sets the strict mode configuration for the JSON parser with default true valuewithStrictMode(boolean mode) Sets the strict mode configuration for the JSON parser.withUseNativeNulls(boolean useNativeNulls) Controls the parser's behavior when meeting Java null values while converting maps.Methods inherited from class org.json.ParserConfiguration
getMaxNestingDepth, getMaxNumberLength, isKeepStrings, withKeepStrings, withMaxNumberLength
-
Constructor Details
-
JSONParserConfiguration
public JSONParserConfiguration()Configuration with the default values.
-
-
Method Details
-
clone
Description copied from class:ParserConfigurationProvides a new instance of the same configuration.- Overrides:
clonein classParserConfiguration
-
withMaxNestingDepth
Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing a map into JSONObject or parsing aCollectioninstance into JSONArray. The default max nesting depth is 512, which means the parser will throw a JsonException if the maximum depth is reached.- Overrides:
withMaxNestingDepthin classParserConfiguration- Parameters:
maxNestingDepth- the maximum nesting depth allowed to the JSON parser- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
withOverwriteDuplicateKey
Controls the parser's behavior when meeting duplicate keys. If set to false, the parser will throw a JSONException when meeting a duplicate key. Or the duplicate key's value will be overwritten.- Parameters:
overwriteDuplicateKey- defines should the parser overwrite duplicate keys.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
withUseNativeNulls
Controls the parser's behavior when meeting Java null values while converting maps. If set to true, the parser will put a JSONObject.NULL into the resulting JSONObject. Or the map entry will be ignored.- Parameters:
useNativeNulls- defines if the parser should convert null values in Java maps- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
withStrictMode
Sets the strict mode configuration for the JSON parser with default true valueWhen strict mode is enabled, the parser will throw a JSONException if it encounters an invalid character immediately following the final ']' character in the input. This is useful for ensuring strict adherence to the JSON syntax, as any characters after the final closing bracket of a JSON array are considered invalid.
- Returns:
- a new JSONParserConfiguration instance with the updated strict mode setting
-
withStrictMode
Sets the strict mode configuration for the JSON parser.When strict mode is enabled, the parser will throw a JSONException if it encounters an invalid character immediately following the final ']' character in the input. This is useful for ensuring strict adherence to the JSON syntax, as any characters after the final closing bracket of a JSON array are considered invalid.
- Parameters:
mode- a boolean value indicating whether strict mode should be enabled or not- Returns:
- a new JSONParserConfiguration instance with the updated strict mode setting
-
isOverwriteDuplicateKey
public boolean isOverwriteDuplicateKey()The parser's behavior when meeting duplicate keys, controls whether the parser should overwrite duplicate keys or not.- Returns:
- The
overwriteDuplicateKeyconfiguration value.
-
isUseNativeNulls
public boolean isUseNativeNulls()The parser's behavior when meeting a null value in a java map, controls whether the parser should write a JSON entry with a null value (isUseNativeNulls() == true) or ignore that map entry (isUseNativeNulls() == false).- Returns:
- The
useNativeNullsconfiguration value.
-
isStrictMode
public boolean isStrictMode()The parser throws an Exception when strict mode is true and tries to parse invalid JSON characters. Otherwise, the parser is more relaxed and might tolerate some invalid characters.- Returns:
- the current strict mode setting.
-