public class JSONConfigDefaults extends Object implements JSONConfigDefaultsMBean, Serializable
This class provides a singleton object which is used to change static
defaults used by JSONConfig and it is used as an MBean to
allow JMX clients with MBean support to view and modify the defaults.
Keep in mind that changes made with this class affect all new
JSONConfig objects created in the same class loader,
including those created by toJSON() methods which don't take a
JSONConfig, which could have undesirable side effects depending
upon your app. Use with care, if at all. All data in this class
is static. The only reason that there is an instance or instance
methods is to support MBean access to the defaults. A few defaults
are only available programmatically. Those are accessed statically.
It is possible to configure most of the default values via JNDI such as is typically available in a web application by adding values to your application's environment under java:/comp/env/org/kopitubruk/util/json. That way you can do things like having all of the validation turned on in development and testing servers and turn it off in production servers for faster performance, without changing any code.
Example for Tomcat, assuming your app is named "MyApp", and your host
is named "host", put this into your
$CATALINA_BASE/conf/Catalina/host/MyApp.xml file in
order to set the appName to "myApp", disable property name validation
and enable using full JSON identifier code points by default:
<Context path="/MyApp">
<Environment name="org/kopitubruk/util/json/appName" type="java.lang.String" value="MyApp" override="false" />
<Environment name="org/kopitubruk/util/json/validatePropertyNames" type="java.lang.Boolean" value="false" override="false" />
<Environment name="org/kopitubruk/util/json/fullJSONIdentifierCodePoints" type="java.lang.Boolean" value="true" override="false" />
</Context>
Because the appName tends to remain consistent across all deployments, it might be preferable to put it into your webapp's web.xml. This should work with all JEE web tier containers. There is a different syntax for adding context environment variables in web.xml:
<env-entry>
<env-entry-name>org/kopitubruk/util/json/appName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>MyApp</env-entry-value>
</env-entry>
You can use this method for any other JNDI environment variables provided that you always want them the same on all deployments.
These are the names and their normal defaults if you don't change them. See their setters for these for descriptions of what they do.
Could cause problems for some things that take JSON. Defaults are for standard JSON. Be careful about changing these.
It is possible to set the default locale in JNDI using the name "locale" and
a String value that is a valid locale string that will get passed to
Locale.forLanguageTag(String). If you don't do this, then the
default locale will be whatever is provided by the JVM.
You can set the default date generation format in JNDI using the name
"dateGenFormat" and a String value that will be passed to
SimpleDateFormat.SimpleDateFormat(String, Locale) using the locale
from getLocale().
You can set any number of default date parsing formats using names that start with "dateParseFormat" followed by some positive base 10 integer (as in "dateParseFormat7") using String values as with "dateGenFormat" described above. They will be added in numeric order of the name.
Classes to use for automatic reflection can be set up via JNDI. This class
will look for String variables named "reflectClass" followed by some positive
base 10 integer (like "reflectClass5"). You can have any number of
reflectClasses. The names merely need to be unique and follow that pattern.
The class names need to load with ClassLoader.loadClass(String) or
they will not be added to the list of reflected classes. If the class
names are followed by a comma and strings separated by commas, those
strings will be taken as field names to use for JSONReflectedClass.
Field names which do not look like valid Java identifier names will be
silently discarded. If the field names are of the form "name=alias"
then a field called "name" will be represented as "alias" in the output.
Aliases do not effect field selection so you can have aliases without
selection. If you want to specify only field "foo" and you want it called
"bar" then you will need to specify "foo,foo=bar" in the string.
These reflect classes will be added to all JSONConfig objects that are created
in the same class loader.
Number formats and date formats are cloned when they are added because they
are not thread safe. They are cloned again when applied to a new
JSONConfig for the same reason. Once you add a format, you can't
modify it except by replacing it entirely.
It is possible to see and modify the default values of all
of the boolean flags at runtime if you have a JMX client
with MBean support connected to your server. It will be in
org.kopitubruk.util.json.JSONConfigDefaults. You can disable MBean
registration by setting a boolean variable named registerMBean to
false in the environment as shown above for the flags. See also the
clearMBean() method for information on how to remove the
MBean from your server when your app is unloaded or reloaded.
There is some limited logging for access of JNDI and the MBean server. Most of it is debug, so you won't see it unless you have debug logging enabled for this package/class. It might be useful to enable debug logging for this class if you are having trouble with those.
You can disable JNDI lookups, MBean registration or logging by defining boolean system properties for org.kopitubruk.util.json.useJNDI, org.kopitubruk.util.json.registerMBean or org.kopitubruk.util.json.logging respectively as false. System properties may be set on the java command line using the "-D" flag or possibly programmatically if your program has permission to do it and does so before this class is loaded. If logging is not set via a system property at all, then JDNI can also be used to disable logging by setting the boolean named "org/kopitubruk/util/json/logging".
You can also set the appName on the command line if you didn't set it in JNDI as in "-Dorg.kopitubruk.util.json.appName=MyApp". The appName is used in the MBean ObjectName and is recommended when this library is used with multiple apps in the same web tier container because it allows you to have different MBeans for different apps at the same time. The appName may also be set via JNDI as a String and that's probably a better way to do it.
JSONConfig,
Serialized Form| Modifier and Type | Method and Description |
|---|---|
static void |
addDateParseFormat(DateFormat fmt)
Add a date parsing format to the list of parsing formats used
by the parser when encodeDatesAsStrings or encodeDatesAsObjects
is true.
|
DateFormat |
addDateParseFormat(String fmtStr)
Add a date parsing format to the list of date parsing formats
used by the parser when encodeDatesAsStrings or
encodeDatesAsObjects is true.
|
static void |
addDateParseFormats(Collection<? extends DateFormat> fmts)
Add a collection of date parsing format to the list of date
parsing formats used by the parser when encodeDatesAsStrings
or encodeDatesAsObjects is true.
|
static void |
addNumberFormat(Class<? extends Number> numericClass,
NumberFormat fmt)
Add a default number format for a particular type that extends Number.
|
static void |
addNumberFormat(Number numericType,
NumberFormat fmt)
Add a default number format for a particular type that extends Number.
|
static void |
addNumberFormats(Map<Class<? extends Number>,NumberFormat> numFmtMap)
Add a map of number formats to the current map of number formats.
|
static void |
addReflectClass(Object obj)
Add the class of the given object to the set of classes that
automatically get reflected.
|
void |
addReflectClassByName(String className)
Add the given class to the set of classes to be reflected.
|
static void |
addReflectClasses(Collection<?> classes)
Add the classes of all of the given objects to the list of classes that
automatically get reflected.
|
void |
clearDateGenFormat()
Clear date generation format.
|
void |
clearDateParseFormats()
Clear any date parse formats from the list of formats used by the parser
when encodeDatesAsStrings or encodeDatesAsObjects is true.
|
static void |
clearMBean()
When this package is used by a webapp, and you have an MBean server in your
environment, then you should create a ServletContextListener and call this
in its ServletContextListener.contextDestroyed(ServletContextEvent)
method to remove the MBean when the webapp is unloaded or reloaded.
|
void |
clearNumberFormats()
Clear any default number formats.
|
void |
clearReflectClasses()
Clear all reflection classes, disabling all default automatic selective
reflection.
|
void |
clearReflectionCache()
Clear the reflection cache, if any.
|
static IndentPadding |
getIndentPadding()
Get the default indent padding object.
|
static JSONConfigDefaults |
getInstance()
Return the JSONConfigDefaults singleton instance.
|
static Locale |
getLocale()
Get the default locale for new
JSONConfig objects. |
String |
getLocaleLanguageTag()
Get the result of
Locale.toLanguageTag() from the current default
locale. |
static NumberFormat |
getNumberFormat(Class<? extends Number> numericClass)
Get the number format for the given class.
|
static NumberFormat |
getNumberFormat(Number num)
Get the number format for the class of the given numeric type.
|
static JSONReflectedClass |
getReflectedClass(Object obj)
Get the
JSONReflectedClass for the given object if it is stored. |
int |
getReflectionPrivacy()
Get the reflection privacy level.
|
int |
getUndefinedCodePointPolicy()
Get the default policy for undefined code points.
|
int |
getUnmatchedSurrogatePolicy()
Get the default policy for unmatched surrogates.
|
boolean |
isAllowReservedWordsInIdentifiers()
Get the default for allowing reserved words in identifiers.
|
boolean |
isCacheReflectionData()
Get the default cacheReflectionData policy.
|
boolean |
isDetectDataStructureLoops()
Get the default detect data structure loops policy.
|
boolean |
isEncodeDatesAsObjects()
Get the encode dates as objects policy.
|
boolean |
isEncodeDatesAsStrings()
Get the encode dates as strings policy.
|
boolean |
isEncodeNumericStringsAsNumbers()
Get the default encode numeric strings as numbers policy.
|
boolean |
isEscapeBadIdentifierCodePoints()
Get the default escape bad identifier code points policy.
|
boolean |
isEscapeNonAscii()
Get the default escape non-ASCII policy.
|
boolean |
isEscapeSurrogates()
Get the default escape surrogates policy.
|
boolean |
isFastStrings()
Get the fastStrings policy.
|
boolean |
isFullJSONIdentifierCodePoints()
Get the full JSON identifier code points policy.
|
boolean |
isPassThroughEscapes()
Get the pass through escapes policy.
|
boolean |
isPreciseNumbers()
Get the default preciseIntegers policy.
|
boolean |
isQuoteIdentifier()
Get the default quote identifier policy.
|
static boolean |
isReflectClass(Object obj)
Return true if the given class is in the set of classes being
automatically reflected.
|
boolean |
isReflectUnknownObjects()
Get the default reflection of unknown objects policy.
|
boolean |
isSmallNumbers()
Get the default smallNumbers policy.
|
boolean |
isUnEscapeWherePossible()
Get the default unEscape policy.
|
boolean |
isUseECMA6()
Get the default escape ECMAScript 6 code points policy.
|
boolean |
isUsePrimitiveArrays()
The default primitive arrays policy.
|
boolean |
isValidatePropertyNames()
Get the default validate property names policy.
|
String |
listReflectedClasses()
Get a string with newline separated list of classes that get reflected.
|
static void |
removeNumberFormat(Class<? extends Number> numericClass)
Remove the requested class from the default number formats.
|
static void |
removeNumberFormat(Number num)
Remove the requested class from the default number formats.
|
static void |
removeReflectClass(Object obj)
Remove the given class from the list of automatically reflected
classes.
|
void |
removeReflectClassByName(String className)
Remove the given class from the set of classes to be reflected.
|
static void |
removeReflectClasses(Collection<?> classes)
Remove the classes of the given objects from the set of classes
that automatically get reflected.
|
void |
setAllowReservedWordsInIdentifiers(boolean dflt)
Set default flag for allowing reserved words in identifiers.
|
static void |
setBadCharacterPolicy(int badCharacterPolicy)
Convenience method to call both
setUnmatchedSurrogatePolicy(int)
and setUndefinedCodePointPolicy(int) using the same value. |
void |
setCacheReflectionData(boolean dflt)
If true, then when an object is reflected its reflection data
will be cached to improve performance on subsequent reflections
of objects of its class.
|
void |
setCodeDefaults()
Reset all defaults to their original unmodified values.
|
static void |
setDateGenFormat(DateFormat fmt)
Set the date string generation format used when encodeDatesAsStrings
or encodeDatesAsObjects is true.
|
DateFormat |
setDateGenFormat(String fmtStr)
Set the date format used for date string generation when
encodeDatesAsStrings or encodeDatesAsObjects is true.
|
void |
setDetectDataStructureLoops(boolean dflt)
Set the default flag for detecting data structure loops.
|
void |
setEncodeDatesAsObjects(boolean dflt)
If true, then
Date objects will be encoded as
Javascript dates, using new Date(dateString). |
void |
setEncodeDatesAsStrings(boolean dflt)
Set the encodeDatesAsStrings policy.
|
void |
setEncodeNumericStringsAsNumbers(boolean dflt)
Set the default flag for encoding of numeric strings as numbers.
|
void |
setEscapeBadIdentifierCodePoints(boolean dflt)
If true, then any bad code points in identifiers will be escaped.
|
void |
setEscapeNonAscii(boolean dflt)
Set the default flag for forcing escaping of non-ASCII characters in
strings and identifiers.
|
void |
setEscapeSurrogates(boolean dflt)
Set the default escapeSurrogates policy.
|
void |
setFastStrings(boolean dflt)
If true, then string values will be copied to the output with no escaping
or validation.
|
void |
setFullJSONIdentifierCodePoints(boolean dflt)
If true, then the full set of identifier code points permitted by the
JSON standard will be allowed instead of the more restrictive set
permitted by the ECMAScript standard.
|
static void |
setIndentPadding(IndentPadding indentPadding)
Set the padding object.
|
static void |
setLocale(Locale loc)
Set a default locale for new
JSONConfig objects to use. |
void |
setLocale(String languageTag)
Deprecated.
Use
setLocaleLanguageTag(String) instead. |
void |
setLocaleLanguageTag(String languageTag)
Set the default locale for new
JSONConfig objects to use by
specifying a IETF BCP 47 language tag suitable for use by
Locale.forLanguageTag(String). |
void |
setPassThroughEscapes(boolean dflt)
If true, then escapes in strings will be passed through unchanged.
|
void |
setPreciseNumbers(boolean dflt)
If true then numbers which are not exactly representable by a 64 bit
double precision floating point number will be quoted in the output.
|
void |
setQuoteIdentifier(boolean dflt)
Set the default flag for forcing quotes on identifiers.
|
void |
setReflectionPrivacy(int dflt)
Set the privacy level for reflection.
|
void |
setReflectUnknownObjects(boolean dflt)
Set the default unknown object reflection encoding policy.
|
void |
setSmallNumbers(boolean dflt)
If true then
JSONParser will attempt to minimize the
storage used for all numbers. |
void |
setUndefinedCodePointPolicy(int dflt)
Tell JSONUtil what to do by default when it encounters undefined code points in strings
and identifiers.
|
void |
setUnEscapeWherePossible(boolean dflt)
Set default flag for undoing inline escapes in strings.
|
void |
setUnmatchedSurrogatePolicy(int dflt)
Tell JSONUtil what to do by default when it encounters unmatched surrogates in strings
and identifiers.
|
void |
setUseECMA6(boolean dflt)
If you set this to true, then by default when JSONUtil generates Unicode
escapes, it will use ECMAScript 6 code point escapes if they are shorter
than code unit escapes.
|
void |
setUsePrimitiveArrays(boolean dflt)
If true, then when
JSONParser encounters a JSON array of non-null
wrappers of primitives and those primitives are all compatible with each
other, then instead of an ArrayList of wrappers for those
primitives it will create an array of those primitives in order to save
memory. |
void |
setValidatePropertyNames(boolean dflt)
Set the default flag for validation of property names.
|
public static void clearMBean()
When this package is used by a webapp, and you have an MBean server in your environment, then you should create a ServletContextListener and call this in its ServletContextListener.contextDestroyed(ServletContextEvent) method to remove the MBean when the webapp is unloaded or reloaded.
public class AppCleanUp implements ServletContextListener
{
public void contextDestroyed( ServletContextEvent sce )
{
JSONConfigDefaults.clearMBean();
}
}
You should add it to your web.xml for your webapp like this (assuming you named it org.myDomain.web.app.AppCleanUp).
<listener>
<listener-class>org.myDomain.web.app.AppCleanUp</listener-class>
</listener>
Note that the logging from this method may not work if the logging is removed/disabled before this method is called.
public static JSONConfigDefaults getInstance()
public void setCodeDefaults()
Accessible via MBean server.
setCodeDefaults in interface JSONConfigDefaultsMBeanpublic String getLocaleLanguageTag()
Locale.toLanguageTag() from the current default
locale.
Accessible via MBean server.
getLocaleLanguageTag in interface JSONConfigDefaultsMBeanpublic void setLocaleLanguageTag(String languageTag)
JSONConfig objects to use by
specifying a IETF BCP 47 language tag suitable for use by
Locale.forLanguageTag(String).
Accessible via MBean server.
setLocaleLanguageTag in interface JSONConfigDefaultsMBeanlanguageTag - A IETF BCP 47 language tag suitable for use by Locale.forLanguageTag(String).@Deprecated public void setLocale(String languageTag)
setLocaleLanguageTag(String) instead.JSONConfig objects to use.languageTag - A language tag suitable for use by Locale.forLanguageTag(String).public static Locale getLocale()
JSONConfig objects. If a
default locale has not been set, then the locale returned
by Locale.getDefault() will be returned.JSONConfig.getLocale()public static void setLocale(Locale loc)
JSONConfig objects to use.loc - the default locale.JSONConfig.setLocale(Locale)public static NumberFormat getNumberFormat(Class<? extends Number> numericClass)
numericClass - A class.JSONConfig.getNumberFormat(Class)public static NumberFormat getNumberFormat(Number num)
num - An object that implements Number.JSONConfig.getNumberFormat(Number)public static void addNumberFormat(Class<? extends Number> numericClass, NumberFormat fmt)
JSONConfig objects that are created after
this in the same class loader. The format is cloned for thread safety.numericClass - The class.fmt - The number format.JSONConfig.addNumberFormat(Class, NumberFormat)public static void addNumberFormat(Number numericType, NumberFormat fmt)
JSONConfig objects that are created after
this in the same class loader. The format is cloned for thread safety.numericType - The object.fmt - The number format.JSONConfig.addNumberFormat(Number, NumberFormat)public static void addNumberFormats(Map<Class<? extends Number>,NumberFormat> numFmtMap)
numFmtMap - The input map.JSONConfig.addNumberFormats(Map)public static void removeNumberFormat(Class<? extends Number> numericClass)
numericClass - The class.JSONConfig.removeNumberFormat(Class)public static void removeNumberFormat(Number num)
num - An object that implements Number.JSONConfig.removeNumberFormat(Number)public void clearNumberFormats()
Accessible via MBean server.
clearNumberFormats in interface JSONConfigDefaultsMBeanJSONConfig.clearNumberFormats()public DateFormat setDateGenFormat(String fmtStr)
Accessible via MBean server.
setDateGenFormat in interface JSONConfigDefaultsMBeanfmtStr - passed to the constructor for
SimpleDateFormat.SimpleDateFormat(String,Locale) using
the result of getLocale().JSONConfig.setDateGenFormat(String)public static void setDateGenFormat(DateFormat fmt)
fmt - the dateFormat to setJSONConfig.setDateGenFormat(DateFormat)public void clearDateGenFormat()
Accessible via MBean server.
clearDateGenFormat in interface JSONConfigDefaultsMBeanJSONConfig.clearDateGenFormat()public DateFormat addDateParseFormat(String fmtStr)
Accessible via MBean server.
addDateParseFormat in interface JSONConfigDefaultsMBeanfmtStr - Passed to
SimpleDateFormat.SimpleDateFormat(String,Locale) using
the result of getLocale().JSONConfig.addDateParseFormat(String)public static void addDateParseFormat(DateFormat fmt)
fmt - A date parsing format.JSONConfig.addDateParseFormat(DateFormat)public static void addDateParseFormats(Collection<? extends DateFormat> fmts)
fmts - A collection of date parsing formats.JSONConfig.addDateParseFormats(Collection)public void clearDateParseFormats()
Accessible via MBean server.
clearDateParseFormats in interface JSONConfigDefaultsMBeanJSONConfig.clearDateParseFormats()public static IndentPadding getIndentPadding()
JSONConfig.getIndentPadding()public static void setIndentPadding(IndentPadding indentPadding)
indentPadding - the default indent padding object.JSONConfig.setIndentPadding(IndentPadding)public int getReflectionPrivacy()
Accessible via MBean server.
getReflectionPrivacy in interface JSONConfigDefaultsMBeanReflectUtil.PRIVATE,
ReflectUtil.PACKAGE,
ReflectUtil.PROTECTED,
ReflectUtil.PUBLIC,
JSONConfig.getReflectionPrivacy()public void setReflectionPrivacy(int dflt)
throws MBeanException
ReflectUtil.PUBLIC.
Accessible via MBean server.
setReflectionPrivacy in interface JSONConfigDefaultsMBeandflt - the level to setMBeanException - If the privacy level is not allowed.ReflectUtil.PRIVATE,
ReflectUtil.PACKAGE,
ReflectUtil.PROTECTED,
ReflectUtil.PUBLIC,
JSONConfig.setReflectionPrivacy(int)public static boolean isReflectClass(Object obj)
obj - An object to checkJSONConfig.isReflectClass(Object)public static JSONReflectedClass getReflectedClass(Object obj)
JSONReflectedClass for the given object if it is stored.
The main reason that you might want to use this is to modify the fields
or aliases that are reflected in the class.obj - The class to look up.JSONConfig.getReflectedClass(Object)public void addReflectClassByName(String className) throws MBeanException
Accessible via MBean server.
This method primarily exists for JMX MBean use.
If you wish to use reflection with fields, you can append the field names to the class name, separated by commas before each field name. Field names which do not look like valid Java identifier names will be silently discarded. For example, if you want to reflect a class called "org.example.Widget" and it has fields called "a", "b" and "c" but you only want "a" and "c", then you can pass "org.example.Widget,a,c" to this method.
If you wish to use custom field names with reflection you can use name=alias pairs separated by commas as with the field names. For example, if you want to reflect a class called "org.example.Widget" and it has a field called "foo" but you want that field encoded as "bar" you can pass "org.example.Widget,foo=bar" to this method.
addReflectClassByName in interface JSONConfigDefaultsMBeanclassName - The name of the class suitable for
ClassLoader.loadClass(String) followed optionally by a
comma separated list of field names and/or field aliases.MBeanException - If there's a problem loading the class.JSONConfig.addReflectClassByName(String)public static void addReflectClass(Object obj)
Iterable or
Enumeration, then all objects in it will be added.obj - The object whose class to add to the reflect list.JSONReflectedClass,
JSONConfig.addReflectClass(Object)public static void addReflectClasses(Collection<?> classes)
classes - The objects to reflect.JSONReflectedClass,
JSONConfig.addReflectClasses(Collection)public void removeReflectClassByName(String className) throws MBeanException
removeReflectClassByName in interface JSONConfigDefaultsMBeanclassName - The name of the class suitable for
(@link ClassLoader.loadClass(String)}.MBeanException - If there's a problem loading the class.public static void removeReflectClass(Object obj)
Iterable or Enumeration,
then all objects in it will be removed.obj - An object of the type to be removed from the reflect list.JSONConfig.removeReflectClass(Object)public static void removeReflectClasses(Collection<?> classes)
classes - The classes to remove.JSONConfig.removeReflectClasses(Collection)public void clearReflectClasses()
Accessible via MBean server.
clearReflectClasses in interface JSONConfigDefaultsMBeanJSONConfig.clearReflectClasses()public void clearReflectionCache()
Accessible via MBean server.
clearReflectionCache in interface JSONConfigDefaultsMBeanpublic String listReflectedClasses()
Accessible via MBean server.
listReflectedClasses in interface JSONConfigDefaultsMBeanpublic int getUnmatchedSurrogatePolicy()
Accessible via MBean server.
getUnmatchedSurrogatePolicy in interface JSONConfigDefaultsMBeanJSONConfig.REPLACE,
JSONConfig.DISCARD,
JSONConfig.EXCEPTION,
JSONConfig.ESCAPE,
JSONConfig.PASS,
JSONConfig.getUnmatchedSurrogatePolicy()public void setUnmatchedSurrogatePolicy(int dflt)
JSONConfig.REPLACE - Replace with Unicode replacement character U+FFFD (default)JSONConfig.DISCARD - Discard them.JSONConfig.EXCEPTION - Throw a UndefinedCodePointExceptionJSONConfig.ESCAPE - Include them but escape themJSONConfig.PASS - Pass them through unmodified.Accessible via MBean server.
setUnmatchedSurrogatePolicy in interface JSONConfigDefaultsMBeandflt - the default unmatchedSurrogatePolicy to setJSONConfig.setUnmatchedSurrogatePolicy(int)public int getUndefinedCodePointPolicy()
Accessible via MBean server.
getUndefinedCodePointPolicy in interface JSONConfigDefaultsMBeanJSONConfig.REPLACE,
JSONConfig.DISCARD,
JSONConfig.EXCEPTION,
JSONConfig.ESCAPE,
JSONConfig.PASS,
JSONConfig.getUndefinedCodePointPolicy()public void setUndefinedCodePointPolicy(int dflt)
JSONConfig.REPLACE - Replace with Unicode replacement character U+FFFD (default)JSONConfig.DISCARD - Discard them.JSONConfig.EXCEPTION - Throw a UndefinedCodePointExceptionJSONConfig.ESCAPE - Include them but escape themJSONConfig.PASS - Pass them through unmodified.Accessible via MBean server.
setUndefinedCodePointPolicy in interface JSONConfigDefaultsMBeandflt - the default undefinedCodePointPolicy to setJSONConfig.setUndefinedCodePointPolicy(int)public static void setBadCharacterPolicy(int badCharacterPolicy)
setUnmatchedSurrogatePolicy(int)
and setUndefinedCodePointPolicy(int) using the same value.badCharacterPolicy - the badCharacterPolicy to setJSONConfig.REPLACE,
JSONConfig.DISCARD,
JSONConfig.EXCEPTION,
JSONConfig.ESCAPE,
JSONConfig.PASS,
JSONConfig.setBadCharacterPolicy(int)public boolean isValidatePropertyNames()
Accessible via MBean server.
isValidatePropertyNames in interface JSONConfigDefaultsMBeanJSONConfig.isValidatePropertyNames()public void setValidatePropertyNames(boolean dflt)
JSONConfig objects created after this call
within the same class loader.
Accessible via MBean server.
setValidatePropertyNames in interface JSONConfigDefaultsMBeandflt - If true, then property names will be validated by default.JSONConfig.setValidatePropertyNames(boolean)public boolean isDetectDataStructureLoops()
isDetectDataStructureLoops in interface JSONConfigDefaultsMBeanJSONConfig.isDetectDataStructureLoops()public void setDetectDataStructureLoops(boolean dflt)
DataStructureLoopException will be thrown.
This will affect all new JSONConfig objects created after this call
within the same class loader.
Accessible via MBean server.
setDetectDataStructureLoops in interface JSONConfigDefaultsMBeandflt - If true, then the code will detect loops in data structures.JSONConfig.setDetectDataStructureLoops(boolean)public boolean isEscapeBadIdentifierCodePoints()
Accessible via MBean server.
isEscapeBadIdentifierCodePoints in interface JSONConfigDefaultsMBeanJSONConfig.isEscapeBadIdentifierCodePoints()public void setEscapeBadIdentifierCodePoints(boolean dflt)
Accessible via MBean server.
setEscapeBadIdentifierCodePoints in interface JSONConfigDefaultsMBeandflt - if true, then any bad code points in identifiers will be escaped.JSONConfig.setEscapeBadIdentifierCodePoints(boolean)public boolean isFullJSONIdentifierCodePoints()
Accessible via MBean server.
isFullJSONIdentifierCodePoints in interface JSONConfigDefaultsMBeanJSONConfig.isFullJSONIdentifierCodePoints()public void setFullJSONIdentifierCodePoints(boolean dflt)
Accessible via MBean server.
setFullJSONIdentifierCodePoints in interface JSONConfigDefaultsMBeandflt - If true, then allow all code points permitted by the JSON standard in identifiers.JSONConfig.setFullJSONIdentifierCodePoints(boolean)public boolean isFastStrings()
isFastStrings in interface JSONConfigDefaultsMBeanJSONConfig.isFastStrings()public void setFastStrings(boolean dflt)
Only use this if you know that you have no unescaped characters in the range U+0000-U+001F or unescaped backslash or forward slash or double quote in your strings. If you want your JSON to be parsable by Javascript eval() then you also need to make sure that you don't have U+2028 (line separator) or U+2029 (paragraph separator).
That said, if you are encoding a lot of large strings, this can improve performance by eliminating the check for characters that need to be escaped.
setFastStrings in interface JSONConfigDefaultsMBeandflt - If true, then string values will be copied as is with no escaping
or validation.JSONConfig.setFastStrings(boolean)public boolean isEncodeNumericStringsAsNumbers()
Accessible via MBean server.
isEncodeNumericStringsAsNumbers in interface JSONConfigDefaultsMBeanJSONConfig.isEncodeNumericStringsAsNumbers()public void setEncodeNumericStringsAsNumbers(boolean dflt)
Accessible via MBean server.
setEncodeNumericStringsAsNumbers in interface JSONConfigDefaultsMBeandflt - If true, then strings that look like valid JSON numbers
will be encoded as numbers.JSONConfig.setEncodeNumericStringsAsNumbers(boolean)public boolean isEscapeNonAscii()
Accessible via MBean server.
isEscapeNonAscii in interface JSONConfigDefaultsMBeanJSONConfig.isEscapeNonAscii()public void setEscapeNonAscii(boolean dflt)
JSONConfig objects created after this
call within the same class loader.
Accessible via MBean server.
setEscapeNonAscii in interface JSONConfigDefaultsMBeandflt - If true, then all non-ASCII will be Unicode escaped.JSONConfig.setEscapeNonAscii(boolean)public boolean isEscapeSurrogates()
Accessible via MBean server.
isEscapeSurrogates in interface JSONConfigDefaultsMBeanJSONConfig.isEscapeSurrogates()public void setEscapeSurrogates(boolean dflt)
Accessible via MBean server.
setEscapeSurrogates in interface JSONConfigDefaultsMBeandflt - If true, then surrogates will be escaped in strings and identifiers
and escapeNonAscii will be forced to false.JSONConfig.setEscapeSurrogates(boolean)public boolean isUnEscapeWherePossible()
Accessible via MBean server.
isUnEscapeWherePossible in interface JSONConfigDefaultsMBeanJSONConfig.isUnEscapeWherePossible()public void setUnEscapeWherePossible(boolean dflt)
Accessible via MBean server.
setUnEscapeWherePossible in interface JSONConfigDefaultsMBeandflt - If true then where possible, undo inline escapes in strings.JSONConfig.setUnEscapeWherePossible(boolean)public boolean isPassThroughEscapes()
Accessible via MBean server.
isPassThroughEscapes in interface JSONConfigDefaultsMBeanJSONConfig.isPassThroughEscapes()public void setPassThroughEscapes(boolean dflt)
Accessible via MBean server.
setPassThroughEscapes in interface JSONConfigDefaultsMBeandflt - If true, then pass escapes through.JSONConfig.setPassThroughEscapes(boolean)public boolean isEncodeDatesAsStrings()
Accessible via MBean server.
isEncodeDatesAsStrings in interface JSONConfigDefaultsMBeanJSONConfig.isEncodeDatesAsStrings()public void setEncodeDatesAsStrings(boolean dflt)
Accessible via MBean server.
setEncodeDatesAsStrings in interface JSONConfigDefaultsMBeandflt - If true, then Date objects will be encoded as ISO 8601 date
strings or a custom date format if you have called
setDateGenFormat(DateFormat).JSONConfig.setEncodeDatesAsStrings(boolean)public boolean isReflectUnknownObjects()
Accessible via MBean server.
isReflectUnknownObjects in interface JSONConfigDefaultsMBeanJSONConfig.isReflectUnknownObjects()public void setReflectUnknownObjects(boolean dflt)
Accessible via MBean server.
setReflectUnknownObjects in interface JSONConfigDefaultsMBeandflt - If true, then attempt to use reflection to encode objects
which are otherwise unknown.addReflectClass(Object),
addReflectClasses(Collection),
addReflectClassByName(String),
JSONConfig.setReflectUnknownObjects(boolean)public boolean isPreciseNumbers()
isPreciseNumbers in interface JSONConfigDefaultsMBeanJSONConfig.isPreciseNumbers()public void setPreciseNumbers(boolean dflt)
setPreciseNumbers in interface JSONConfigDefaultsMBeandflt - If true then quote numbers that lose precision in 64-bit floating point.JSONConfig.setPreciseNumbers(boolean)public boolean isSmallNumbers()
isSmallNumbers in interface JSONConfigDefaultsMBeanJSONConfig.isSmallNumbers()public void setSmallNumbers(boolean dflt)
JSONParser will attempt to minimize the
storage used for all numbers. Decimal numbers will be reduced
to floats instead of doubles if it can done without losing
precision. Integer numbers will be reduced from long to int
or short or byte if they fit.setSmallNumbers in interface JSONConfigDefaultsMBeandflt - If true then numbers will be made to use as little memory as possible.JSONConfig.setSmallNumbers(boolean)public boolean isUsePrimitiveArrays()
isUsePrimitiveArrays in interface JSONConfigDefaultsMBeanJSONConfig.isUsePrimitiveArrays()public void setUsePrimitiveArrays(boolean dflt)
JSONParser encounters a JSON array of non-null
wrappers of primitives and those primitives are all compatible with each
other, then instead of an ArrayList of wrappers for those
primitives it will create an array of those primitives in order to save
memory.
This works for booleans and numbers. It will also convert an array of single character strings into an array of chars. Arrays of numbers will attempt to use the least complex type that does not lose information. You could easily end up with an array of bytes if all of your numbers are integers in the range -128 to 127. This option is meant to save as much memory as possible.
setUsePrimitiveArrays in interface JSONConfigDefaultsMBeandflt - if true, then the parser will create arrays of primitives as applicable.JSONConfig.setUsePrimitiveArrays(boolean)public boolean isCacheReflectionData()
isCacheReflectionData in interface JSONConfigDefaultsMBeanJSONConfig.isCacheReflectionData()public void setCacheReflectionData(boolean dflt)
setCacheReflectionData in interface JSONConfigDefaultsMBeandflt - if true, then cache reflection data.JSONConfig.setCacheReflectionData(boolean)public boolean isQuoteIdentifier()
Accessible via MBean server.
isQuoteIdentifier in interface JSONConfigDefaultsMBeanJSONConfig.isQuoteIdentifier()public void setQuoteIdentifier(boolean dflt)
JSONConfig objects created after this call
within the same class loader.
Accessible via MBean server.
setQuoteIdentifier in interface JSONConfigDefaultsMBeandflt - If true, then all identifiers will be quoted.JSONConfig.setQuoteIdentifier(boolean)public boolean isUseECMA6()
Accessible via MBean server.
isUseECMA6 in interface JSONConfigDefaultsMBeanJSONConfig.isUseECMA6()public void setUseECMA6(boolean dflt)
Accessible via MBean server.
setUseECMA6 in interface JSONConfigDefaultsMBeandflt - If true, use EMCAScript 6 code point escapes and allow
ECMAScript 6 identifier character set.JSONConfig.setUseECMA6(boolean)public boolean isAllowReservedWordsInIdentifiers()
Accessible via MBean server.
isAllowReservedWordsInIdentifiers in interface JSONConfigDefaultsMBeanJSONConfig.isAllowReservedWordsInIdentifiers()public void setAllowReservedWordsInIdentifiers(boolean dflt)
Accessible via MBean server.
setAllowReservedWordsInIdentifiers in interface JSONConfigDefaultsMBeandflt - If true, then reserved words will be allowed in identifiers.JSONConfig.setAllowReservedWordsInIdentifiers(boolean)public boolean isEncodeDatesAsObjects()
Accessible via MBean server.
isEncodeDatesAsObjects in interface JSONConfigDefaultsMBeanJSONConfig.isEncodeDatesAsObjects()public void setEncodeDatesAsObjects(boolean dflt)
Date objects will be encoded as
Javascript dates, using new Date(dateString). If you
set this to true, then encodeDatesAsStrings will be
set to false.
Accessible via MBean server.
setEncodeDatesAsObjects in interface JSONConfigDefaultsMBeandflt - If true, then Date objects will be encoded as
Javascript dates.JSONConfig.setEncodeDatesAsObjects(boolean)Copyright © 2016. All rights reserved.