Package org.json
Class XMLParserConfiguration
java.lang.Object
org.json.XMLParserConfiguration
Configuration object for the XML parser. The configuration is immutable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The name of the key in a JSON Object that indicates a CDATA section.private boolean
When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false
), or they should be converted tonull
(true
)When parsing the XML into JSON, specifies the tags whose values should be converted to arraysstatic final XMLParserConfiguration
Original configuration of the XML Parser except that values are kept as strings.private boolean
When parsing the XML into JSON, specifies if values should be kept as strings (true
), or if they should try to be guessed into JSON values (numeric, boolean, string)static final XMLParserConfiguration
Original Configuration of the XML Parser.private Map
<String, XMLXsiTypeConverter<?>> This will allow type conversion for values in XML if xsi:type attribute is defined -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefault parser configuration.XMLParserConfiguration
(boolean keepStrings) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration.XMLParserConfiguration
(boolean keepStrings, String cDataTagName) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration.XMLParserConfiguration
(boolean keepStrings, String cDataTagName, boolean convertNilAttributeToNull) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration.private
XMLParserConfiguration
(boolean keepStrings, String cDataTagName, boolean convertNilAttributeToNull, Map<String, XMLXsiTypeConverter<?>> xsiTypeMap, Set<String> forceList) Configure the parser to use custom settings.XMLParserConfiguration
(String cDataTagName) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected XMLParserConfiguration
clone()
Provides a new instance of the same configuration.The name of the key in a JSON Object that indicates a CDATA section.When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>
to parse the provided tags' values as arraysWhen parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>
to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as stringboolean
When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false
), or they should be converted tonull
(true
)boolean
When parsing the XML into JSON, specifies if values should be kept as strings (true
), or if they should try to be guessed into JSON values (numeric, boolean, string)withcDataTagName
(String newVal) The name of the key in a JSON Object that indicates a CDATA section.withConvertNilAttributeToNull
(boolean newVal) When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false
), or they should be converted tonull
(true
)withForceList
(Set<String> forceList) When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>
to parse the provided tags' values as arrayswithKeepStrings
(boolean newVal) When parsing the XML into JSON, specifies if values should be kept as strings (true
), or if they should try to be guessed into JSON values (numeric, boolean, string)withXsiTypeMap
(Map<String, XMLXsiTypeConverter<?>> xsiTypeMap) When parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>
to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string
-
Field Details
-
ORIGINAL
Original Configuration of the XML Parser. -
KEEP_STRINGS
Original configuration of the XML Parser except that values are kept as strings. -
keepStrings
private boolean keepStringsWhen parsing the XML into JSON, specifies if values should be kept as strings (true
), or if they should try to be guessed into JSON values (numeric, boolean, string) -
cDataTagName
The name of the key in a JSON Object that indicates a CDATA section. Historically this has been the value "content" but can be changed. Usenull
to indicate no CDATA processing. -
convertNilAttributeToNull
private boolean convertNilAttributeToNullWhen parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false
), or they should be converted tonull
(true
) -
xsiTypeMap
This will allow type conversion for values in XML if xsi:type attribute is defined -
forceList
When parsing the XML into JSON, specifies the tags whose values should be converted to arrays
-
-
Constructor Details
-
XMLParserConfiguration
public XMLParserConfiguration()Default parser configuration. Does not keep strings (tries to implicitly convert values), and the CDATA Tag Name is "content". -
XMLParserConfiguration
Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed in a future release.Configure the parser string processing and use the default CDATA Tag Name as "content".- Parameters:
keepStrings
-true
to parse all values as string.false
to try and convert XML string values into a JSON value.
-
XMLParserConfiguration
Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed in a future release.Configure the parser string processing to try and convert XML values to JSON values and use the passed CDATA Tag Name the processing value. Passnull
to disable CDATA processing- Parameters:
cDataTagName
-null
to disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.
-
XMLParserConfiguration
Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed in a future release.Configure the parser to use custom settings.- Parameters:
keepStrings
-true
to parse all values as string.false
to try and convert XML string values into a JSON value.cDataTagName
-null
to disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.
-
XMLParserConfiguration
@Deprecated public XMLParserConfiguration(boolean keepStrings, String cDataTagName, boolean convertNilAttributeToNull) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed or marked private in a future release.Configure the parser to use custom settings.- Parameters:
keepStrings
-true
to parse all values as string.false
to try and convert XML string values into a JSON value.cDataTagName
-null
to disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.convertNilAttributeToNull
-true
to parse values with attribute xsi:nil="true" as null.false
to parse values with attribute xsi:nil="true" as {"xsi:nil":true}.
-
XMLParserConfiguration
private XMLParserConfiguration(boolean keepStrings, String cDataTagName, boolean convertNilAttributeToNull, Map<String, XMLXsiTypeConverter<?>> xsiTypeMap, Set<String> forceList) Configure the parser to use custom settings.- Parameters:
keepStrings
-true
to parse all values as string.false
to try and convert XML string values into a JSON value.cDataTagName
-null
to disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.convertNilAttributeToNull
-true
to parse values with attribute xsi:nil="true" as null.false
to parse values with attribute xsi:nil="true" as {"xsi:nil":true}.xsiTypeMap
-new HashMapinvalid input: '<'String, XMLXsiTypeConverterinvalid input: '<'?>>()
to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as stringforceList
-new HashSet
to parse the provided tags' values as arrays()
-
-
Method Details
-
clone
Provides a new instance of the same configuration. -
isKeepStrings
public boolean isKeepStrings()When parsing the XML into JSON, 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
When parsing the XML into JSON, specifies if values should be kept as strings (true
), or if they should try to be guessed into JSON values (numeric, boolean, string)- Parameters:
newVal
- new value to use for thekeepStrings
configuration option.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
getcDataTagName
The name of the key in a JSON Object that indicates a CDATA section. Historically this has been the value "content" but can be changed. Usenull
to indicate no CDATA processing.- Returns:
- The
cDataTagName
configuration value.
-
withcDataTagName
The name of the key in a JSON Object that indicates a CDATA section. Historically this has been the value "content" but can be changed. Usenull
to indicate no CDATA processing.- Parameters:
newVal
- new value to use for thecDataTagName
configuration option.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
isConvertNilAttributeToNull
public boolean isConvertNilAttributeToNull()When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false
), or they should be converted tonull
(true
)- Returns:
- The
convertNilAttributeToNull
configuration value.
-
withConvertNilAttributeToNull
When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false
), or they should be converted tonull
(true
)- Parameters:
newVal
- new value to use for theconvertNilAttributeToNull
configuration option.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
getXsiTypeMap
When parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>
to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string- Returns:
xsiTypeMap
unmodifiable configuration map.
-
withXsiTypeMap
When parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>
to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string- Parameters:
xsiTypeMap
-new HashMap<String, XMLXsiTypeConverter<?>>()
to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
getForceList
When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>
to parse the provided tags' values as arrays- Returns:
forceList
unmodifiable configuration set.
-
withForceList
When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>
to parse the provided tags' values as arrays- Parameters:
forceList
-new HashSet<String>()
to parse the provided tags' values as arrays- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-