public class JSONConfig extends Object implements Serializable, Cloneable
It is possible to change the defaults by using the
JSONConfigDefaults class. See that class for details.
These are the names of the boolean flags and their normal defaults if you don't change them. See the setters for these for descriptions of what they do.
This could cause problems for some things that take JSON. Defaults are for standard JSON. Be careful about changing these. They should work fine if the JSON is interpreted by a standard Javascript eval(), except ECMAScript 6 code points if your interpreter doesn't support those. Going non-default on any of these tends not to work in strict JSON parsers such as JQuery.
You can change the locale being used for error messages and log messages and possibly by JSONAble objects for encoding.
You can create number formats associated with specific numeric types if you want your numbers encoded in a certain way.
JSONConfigDefaults,
Serialized Form| Constructor and Description |
|---|
JSONConfig()
Create a JSONConfig
|
JSONConfig(Locale locale)
Create a JSONConfig with the given locale.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addNumberFormat(Class<? extends Number> numericClass,
NumberFormat fmt)
Add a number format for a particular type that extends Number.
|
void |
addNumberFormat(Number numericType,
NumberFormat fmt)
Add a number format for a particular type that extends Number.
|
void |
clearNumberFormats()
Clear all number formats.
|
JSONConfig |
clone()
Return a clone of this object.
|
Locale |
getLocale()
Get the locale.
|
NumberFormat |
getNumberFormat(Class<? extends Number> numericClass)
Get the number format for the given class.
|
NumberFormat |
getNumberFormat(Number num)
Get the number format for the class of th given numeric type.
|
boolean |
isAllowReservedWordsInIdentifiers()
Get the allowReservedWordsInIdentifiers policy.
|
boolean |
isDetectDataStructureLoops()
Return true if data structure loops will be detected.
|
boolean |
isEncodeNumericStringsAsNumbers()
If true, then strings will be checked for number patterns and if they
look like numbers, then they won't be quoted.
|
boolean |
isEscapeBadIdentifierCodePoints()
Find out if bad identifier code points will be escaped.
|
boolean |
isEscapeNonAscii()
Check if non-ascii characters are to be encoded as Unicode escapes.
|
boolean |
isEscapeSurrogates()
Return the escape surrogates policy.
|
boolean |
isQuoteIdentifier()
Find out what the identifier quote policy is.
|
boolean |
isUnEscapeWherePossible()
The unEscape policy.
|
boolean |
isUseECMA6()
Find out if ECMAScript 6 code point escapes are enabled.
|
boolean |
isValidatePropertyNames()
Check if property names will be validated.
|
void |
removeNumberFormat(Class<? extends Number> numericClass)
Remove the requested class from the number formats that
this config knows about.
|
void |
removeNumberFormat(Number num)
Remove the requested class from the number formats that
this config knows about.
|
void |
setAllowReservedWordsInIdentifiers(boolean allowReservedWordsInIdentifiers)
If true then reserved words will be allowed in identifiers even when
identifier validation is enabled.
|
void |
setDetectDataStructureLoops(boolean detectDataStructureLoops)
Enable or disable data structure loop detection.
|
void |
setEncodeNumericStringsAsNumbers(boolean encodeNumericStringsAsNumbers)
If true, then strings will be checked for number patterns and if they
look like numbers, then they won't be quoted.
|
void |
setEscapeBadIdentifierCodePoints(boolean escapeBadIdentifierCodePoints)
If true, then any bad code points in identifiers will be escaped.
|
void |
setEscapeNonAscii(boolean escapeNonAscii)
If you want non-ascii characters encoded as Unicode escapes, you can do
that by setting this to true.
|
void |
setEscapeSurrogates(boolean escapeSurrogates)
If true then all surrogates will be escaped.
|
void |
setLocale(Locale locale)
Set the locale.
|
void |
setQuoteIdentifier(boolean quoteIdentifier)
Control whether identifiers are quoted or not.
|
void |
setUnEscapeWherePossible(boolean unEscapeWherePossible)
If true then where possible, undo inline escapes in strings.
|
void |
setUseECMA6(boolean useECMA6)
If you set this to true, then when the JSONUtil generates Unicode
escapes, it will use ECMAScript 6 code point escapes if they are shorter
than code unit escapes.
|
void |
setValidatePropertyNames(boolean validatePropertyNames)
If true, then property names will be validated.
|
public JSONConfig()
public JSONConfig(Locale locale)
locale - the locale to set.public JSONConfig clone()
public Locale getLocale()
public void setLocale(Locale locale)
JSONAble's
that can use a locale.locale - the locale to setpublic void addNumberFormat(Class<? extends Number> numericClass, NumberFormat fmt)
This could allow you to limit the number of digits printed for a float or a double for example, getting rid of excess digits caused by rounding problems in floating point numbers.
numericClass - The class.fmt - The number format.public void addNumberFormat(Number numericType, NumberFormat fmt)
This could allow you to limit the number of digits printed for a float or a double for example, getting rid of excess digits caused by rounding problems in floating point numbers.
numericType - The object.fmt - The number format.public NumberFormat getNumberFormat(Class<? extends Number> numericClass)
numericClass - A class.public NumberFormat getNumberFormat(Number num)
num - An object that implements Number.public void removeNumberFormat(Class<? extends Number> numericClass)
numericClass - The class.public void removeNumberFormat(Number num)
num - An object that implements Number.public void clearNumberFormats()
public boolean isValidatePropertyNames()
public void setValidatePropertyNames(boolean validatePropertyNames)
When validation is enabled, only code points which are allowed in identifiers will be permitted as per the ECMAScript 5 or 6 standard as well as disallowing reserved words as per the JSON spec. It will also check for duplicate property names in the same object, which is possible because keys in maps are not required to be String objects and it's possible (though not likely) for two objects which are not equal to have the same result from a toString() method.
validatePropertyNames - Set to false to disable property name validation.public boolean isDetectDataStructureLoops()
public void setDetectDataStructureLoops(boolean detectDataStructureLoops)
detectDataStructureLoops - If true then JSONUtil will attempt to detect loops in data structures.public boolean isEscapeBadIdentifierCodePoints()
public void setEscapeBadIdentifierCodePoints(boolean escapeBadIdentifierCodePoints)
escapeBadIdentifierCodePoints - the escapeBadIdentifierCodePoints to setpublic boolean isEncodeNumericStringsAsNumbers()
public void setEncodeNumericStringsAsNumbers(boolean encodeNumericStringsAsNumbers)
encodeNumericStringsAsNumbers - the encodeNumericStringsAsNumbers to setpublic boolean isEscapeNonAscii()
public void setEscapeNonAscii(boolean escapeNonAscii)
escapeNonAscii - set to true if you want non-ascii to be Unicode escaped.public boolean isUnEscapeWherePossible()
public void setUnEscapeWherePossible(boolean unEscapeWherePossible)
Note that this does not apply to property names. It is only applied to string values.
unEscapeWherePossible - If true then where possible, undo inline
escapes in strings.public boolean isEscapeSurrogates()
public void setEscapeSurrogates(boolean escapeSurrogates)
escapeSurrogates - the escapeSurrogates to setpublic boolean isQuoteIdentifier()
public void setQuoteIdentifier(boolean quoteIdentifier)
quoteIdentifier - If true, then all identifiers will be quoted. If
false, then only those that really need quotes will be quoted.public boolean isUseECMA6()
public void setUseECMA6(boolean useECMA6)
useECMA6 - If true, use EMCAScript 6 code point escapes and allow
ECMAScript 6 identifier character set.public boolean isAllowReservedWordsInIdentifiers()
public void setAllowReservedWordsInIdentifiers(boolean allowReservedWordsInIdentifiers)
allowReservedWordsInIdentifiers - the allowReservedWordsInIdentifiers to setCopyright © 2015. All rights reserved.