net.sf.json
Class JsonConfig

java.lang.Object
  extended by net.sf.json.JsonConfig

public class JsonConfig
extends java.lang.Object

Utility class that helps configuring the serialization process.

Author:
Andres Almiray

Field Summary
static JsonBeanProcessorMatcher DEFAULT_JSON_BEAN_PROCESSOR_MATCHER
           
static NewBeanInstanceStrategy DEFAULT_NEW_BEAN_INSTANCE_STRATEGY
           
static int MODE_LIST
           
static int MODE_OBJECT_ARRAY
           
 
Constructor Summary
JsonConfig()
           
 
Method Summary
 void addJsonEventListener(JsonEventListener listener)
          Registers a listener for Json events.
The events will be triggered only when using the static builders and if event triggering is enabled.
 void clearJsonBeanProcessors()
          Removes all registered JsonBeanProcessors.
 void clearJsonEventListeners()
          Removes all registered listener for Json Events.
 void clearJsonValueProcessors()
          Removes all registered JsonValueProcessors.
 JsonConfig copy()
           
 void disableEventTriggering()
          Disables event triggering when building.
 void enableEventTriggering()
          Enables event triggering when building.
 JsonBeanProcessor findJsonBeanProcessor(java.lang.Class target)
          Finds a JsonBeanProcessor registered to the target class.
Returns null if none is registered.
 JsonValueProcessor findJsonValueProcessor(java.lang.Class propertyType)
          Finds a JsonValueProcessor registered to the target type.
Returns null if none is registered.
 JsonValueProcessor findJsonValueProcessor(java.lang.Class beanClass, java.lang.Class propertyType, java.lang.String key)
          Finds a JsonValueProcessor.
It will search the registered JsonValueProcessors in the following order: beanClass, key beanClass, type key type Returns null if none is registered.
 JsonValueProcessor findJsonValueProcessor(java.lang.Class propertyType, java.lang.String key)
          Finds a JsonValueProcessor.
It will search the registered JsonValueProcessors in the following order: key type Returns null if none is registered.
 int getArrayMode()
          Returns the current array mode conversion
 java.util.Map getClassMap()
          Returns the current attribute/class Map
 CycleDetectionStrategy getCycleDetectionStrategy()
          Returns the configured CycleDetectionStrategy.
Default value is CycleDetectionStrategy.STRICT
 java.lang.String[] getExcludes()
          Returns the configured properties for exclusion.
 JavaIdentifierTransformer getJavaIdentifierTransformer()
          Returns the configured JavaIdentifierTransformer.
 PropertyFilter getJavaPropertyFilter()
          Returns the configured property filter when serializing to Java.
 JsonBeanProcessorMatcher getJsonBeanProcessorMatcher()
          Returns the configured JsonBeanProcessorMatcher.
Default value is JsonBeanProcessorMatcher.DEFAULT
 java.util.List getJsonEventListeners()
          Returns a list of registered listeners for Json events.
 PropertyFilter getJsonPropertyFilter()
          Returns the configured property filter when serializing to JSON.
 java.util.Collection getMergedExcludes()
          Returns a set of default excludes with user-defined excludes.
 NewBeanInstanceStrategy getNewBeanInstanceStrategy()
          Returns the configured NewBeanInstanceStrategy.
Default value is NewBeanInstanceStrategy.DEFAULT
 java.lang.Class getRootClass()
          Returns the current root Class.
 boolean isEventTriggeringEnabled()
          Returns true if event triggering is enabled during building.
Default value is false
 boolean isHandleJettisonEmptyElement()
          Returns true if this jettison convention will be handled when converting to Java.
Jettison assumes that "" (empty string) can be assigned to empty elements (objects), which clearly violates the JSON spec.
 boolean isHandleJettisonSingleElementArray()
          Returns true if this jettison convention will be handled when converting to Java.
Jettison states the following JSON {'media':{'title':'hello'}} can be set as a single element JSONArray (media is the array).
 boolean isIgnoreDefaultExcludes()
          Returns true if default excludes will not be used.
Default value is false
 boolean isIgnoreTransientFields()
          Returns true if transient fields of a bean will be ignored.
Default value is false
 boolean isSkipJavaIdentifierTransformationInMapKeys()
          Returns true if map keys will not be transformed.
Default value is false
 void registerJsonBeanProcessor(java.lang.Class target, JsonBeanProcessor jsonBeanProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(java.lang.Class beanClass, java.lang.Class propertyType, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(java.lang.Class propertyType, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(java.lang.Class beanClass, java.lang.String key, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(java.lang.String key, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void removeJsonEventListener(JsonEventListener listener)
          Removes a listener for Json events.
 void reset()
          Resets all values to its default state.
 void setArrayMode(int arrayMode)
          Sets the current array mode for conversion.
If the value is not MODE_LIST neither MODE_OBJECT_ARRAY, then MODE_LIST will be used.
 void setClassMap(java.util.Map classMap)
          Sets the current attribute/Class Map
 void setCycleDetectionStrategy(CycleDetectionStrategy cycleDetectionStrategy)
          Sets a CycleDetectionStrategy to use.
Will set default value (CycleDetectionStrategy.STRICT) if null.
 void setExcludes(java.lang.String[] excludes)
          Sets the excludes to use.
Will set default value ([]) if null.
 void setHandleJettisonEmptyElement(boolean handleJettisonEmptyElement)
          Activate/Deactive handling this jettison convention when converting to Java.
Jettison states that "" (empty string) can be assigned to empty elements (objects), which clearly violates the JSON spec.
 void setHandleJettisonSingleElementArray(boolean handleJettisonSingleElementArray)
          Activate/Deactive handling this jettison convention when converting to Java.
* Jettison states the following JSON {'media':{'title':'hello'}} can be set as a single element JSONArray (media is the array).
 void setIgnoreDefaultExcludes(boolean ignoreDefaultExcludes)
          Sets if default ecludes would be skipped when building.
 void setIgnoreTransientFields(boolean ignoreTransientFields)
          Sets if transient fields would be skipped when building.
 void setJavaIdentifierTransformer(JavaIdentifierTransformer javaIdentifierTransformer)
          Sets the JavaIdentifierTransformer to use.
Will set default value (JavaIdentifierTransformer.NOOP) if null.
 void setJavaPropertyFilter(PropertyFilter javaPropertyFilter)
          Sets a property filter used when serializing to Java.
 void setJsonBeanProcessorMatcher(JsonBeanProcessorMatcher jsonBeanProcessorMatcher)
          Sets a JsonBeanProcessorMatcher to use.
Will set default value (JsonBeanProcessorMatcher.STRICT) if null.
 void setJsonPropertyFilter(PropertyFilter jsonPropertyFilter)
          Sets a property filter used when serializing to JSON.
 void setNewBeanInstanceStrategy(NewBeanInstanceStrategy newBeanInstanceStrategy)
          Sets the NewBeanInstanceStrategy to use.
Will set default value (NewBeanInstanceStrategy.DEFAULT) if null.
 void setRootClass(java.lang.Class rootClass)
          Sets the current root Class
 void setSkipJavaIdentifierTransformationInMapKeys(boolean skipJavaIdentifierTransformationInMapKeys)
          Sets if transient fields of beans would be skipped when building.
 void unregisterJsonBeanProcessor(java.lang.Class target)
          Removes a JsonBeanProcessor.
 void unregisterJsonValueProcessor(java.lang.Class propertyType)
          Removes a JsonValueProcessor.
 void unregisterJsonValueProcessor(java.lang.Class beanClass, java.lang.Class propertyType)
          Removes a JsonValueProcessor.
 void unregisterJsonValueProcessor(java.lang.Class beanClass, java.lang.String key)
          Removes a JsonValueProcessor.
 void unregisterJsonValueProcessor(java.lang.String key)
          Removes a JsonValueProcessor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_JSON_BEAN_PROCESSOR_MATCHER

public static final JsonBeanProcessorMatcher DEFAULT_JSON_BEAN_PROCESSOR_MATCHER

DEFAULT_NEW_BEAN_INSTANCE_STRATEGY

public static final NewBeanInstanceStrategy DEFAULT_NEW_BEAN_INSTANCE_STRATEGY

MODE_LIST

public static final int MODE_LIST
See Also:
Constant Field Values

MODE_OBJECT_ARRAY

public static final int MODE_OBJECT_ARRAY
See Also:
Constant Field Values
Constructor Detail

JsonConfig

public JsonConfig()
Method Detail

addJsonEventListener

public void addJsonEventListener(JsonEventListener listener)
Registers a listener for Json events.
The events will be triggered only when using the static builders and if event triggering is enabled.

Parameters:
listener - a listener for events
See Also:
enableEventTriggering(), disableEventTriggering(), removeJsonEventListener(JsonEventListener)

clearJsonBeanProcessors

public void clearJsonBeanProcessors()
Removes all registered JsonBeanProcessors.


clearJsonEventListeners

public void clearJsonEventListeners()
Removes all registered listener for Json Events.


clearJsonValueProcessors

public void clearJsonValueProcessors()
Removes all registered JsonValueProcessors.


copy

public JsonConfig copy()

disableEventTriggering

public void disableEventTriggering()
Disables event triggering when building.


enableEventTriggering

public void enableEventTriggering()
Enables event triggering when building.


findJsonBeanProcessor

public JsonBeanProcessor findJsonBeanProcessor(java.lang.Class target)
Finds a JsonBeanProcessor registered to the target class.
Returns null if none is registered.
Used when tramsforming from Java to Json.

Parameters:
target - a class used for searching a JsonBeanProcessor.

findJsonValueProcessor

public JsonValueProcessor findJsonValueProcessor(java.lang.Class propertyType)
Finds a JsonValueProcessor registered to the target type.
Returns null if none is registered.
Used when tramsforming from Java to Json.

Parameters:
propertyType - a class used for searching a JsonValueProcessor.

findJsonValueProcessor

public JsonValueProcessor findJsonValueProcessor(java.lang.Class beanClass,
                                                 java.lang.Class propertyType,
                                                 java.lang.String key)
Finds a JsonValueProcessor.
It will search the registered JsonValueProcessors in the following order:
  1. beanClass, key
  2. beanClass, type
  3. key
  4. type
Returns null if none is registered.
Used when tramsforming from Java to Json.

Parameters:
beanClass - the class to which the property may belong
propertyType - the type of the property
key - the name of the property which may belong to the target class

findJsonValueProcessor

public JsonValueProcessor findJsonValueProcessor(java.lang.Class propertyType,
                                                 java.lang.String key)
Finds a JsonValueProcessor.
It will search the registered JsonValueProcessors in the following order:
  1. key
  2. type
Returns null if none is registered.
Used when tramsforming from Java to Json.

Parameters:
propertyType - the type of the property
key - the name of the property which may belong to the target class

getArrayMode

public int getArrayMode()
Returns the current array mode conversion

Returns:
either MODE_OBJECT_ARRAY or MODE_LIST

getClassMap

public java.util.Map getClassMap()
Returns the current attribute/class Map

Returns:
a Map of classes, every key identifies a property or a regexp

getCycleDetectionStrategy

public CycleDetectionStrategy getCycleDetectionStrategy()
Returns the configured CycleDetectionStrategy.
Default value is CycleDetectionStrategy.STRICT


getExcludes

public java.lang.String[] getExcludes()
Returns the configured properties for exclusion.
Used when tramsforming from Java to Json.


getJavaIdentifierTransformer

public JavaIdentifierTransformer getJavaIdentifierTransformer()
Returns the configured JavaIdentifierTransformer.
Used when transforming from Json to Java.
Default value is JavaIdentifierTransformer.NOOP


getJavaPropertyFilter

public PropertyFilter getJavaPropertyFilter()
Returns the configured property filter when serializing to Java.


getJsonBeanProcessorMatcher

public JsonBeanProcessorMatcher getJsonBeanProcessorMatcher()
Returns the configured JsonBeanProcessorMatcher.
Default value is JsonBeanProcessorMatcher.DEFAULT


getJsonEventListeners

public java.util.List getJsonEventListeners()
Returns a list of registered listeners for Json events.


getJsonPropertyFilter

public PropertyFilter getJsonPropertyFilter()
Returns the configured property filter when serializing to JSON.


getMergedExcludes

public java.util.Collection getMergedExcludes()
Returns a set of default excludes with user-defined excludes.


getNewBeanInstanceStrategy

public NewBeanInstanceStrategy getNewBeanInstanceStrategy()
Returns the configured NewBeanInstanceStrategy.
Default value is NewBeanInstanceStrategy.DEFAULT


getRootClass

public java.lang.Class getRootClass()
Returns the current root Class.

Returns:
the target class for conversion

isEventTriggeringEnabled

public boolean isEventTriggeringEnabled()
Returns true if event triggering is enabled during building.
Default value is false


isHandleJettisonEmptyElement

public boolean isHandleJettisonEmptyElement()
Returns true if this jettison convention will be handled when converting to Java.
Jettison assumes that "" (empty string) can be assigned to empty elements (objects), which clearly violates the JSON spec.


isHandleJettisonSingleElementArray

public boolean isHandleJettisonSingleElementArray()
Returns true if this jettison convention will be handled when converting to Java.
Jettison states the following JSON {'media':{'title':'hello'}} can be set as a single element JSONArray (media is the array).


isIgnoreDefaultExcludes

public boolean isIgnoreDefaultExcludes()
Returns true if default excludes will not be used.
Default value is false


isIgnoreTransientFields

public boolean isIgnoreTransientFields()
Returns true if transient fields of a bean will be ignored.
Default value is false


isSkipJavaIdentifierTransformationInMapKeys

public boolean isSkipJavaIdentifierTransformationInMapKeys()
Returns true if map keys will not be transformed.
Default value is false


registerJsonBeanProcessor

public void registerJsonBeanProcessor(java.lang.Class target,
                                      JsonBeanProcessor jsonBeanProcessor)
Registers a JsonValueProcessor.

Parameters:
target - the class to use as key
jsonBeanProcessor - the processor to register

registerJsonValueProcessor

public void registerJsonValueProcessor(java.lang.Class beanClass,
                                       java.lang.Class propertyType,
                                       JsonValueProcessor jsonValueProcessor)
Registers a JsonValueProcessor.

Parameters:
beanClass - the class to use as key
propertyType - the property type to use as key
jsonValueProcessor - the processor to register

registerJsonValueProcessor

public void registerJsonValueProcessor(java.lang.Class propertyType,
                                       JsonValueProcessor jsonValueProcessor)
Registers a JsonValueProcessor.

Parameters:
propertyType - the property type to use as key
jsonValueProcessor - the processor to register

registerJsonValueProcessor

public void registerJsonValueProcessor(java.lang.Class beanClass,
                                       java.lang.String key,
                                       JsonValueProcessor jsonValueProcessor)
Registers a JsonValueProcessor.

Parameters:
beanClass - the class to use as key
key - the property name to use as key
jsonValueProcessor - the processor to register

registerJsonValueProcessor

public void registerJsonValueProcessor(java.lang.String key,
                                       JsonValueProcessor jsonValueProcessor)
Registers a JsonValueProcessor.

Parameters:
key - the property name to use as key
jsonValueProcessor - the processor to register

removeJsonEventListener

public void removeJsonEventListener(JsonEventListener listener)
Removes a listener for Json events.

Parameters:
listener - a listener for events
See Also:
addJsonEventListener(JsonEventListener)

reset

public void reset()
Resets all values to its default state.


setArrayMode

public void setArrayMode(int arrayMode)
Sets the current array mode for conversion.
If the value is not MODE_LIST neither MODE_OBJECT_ARRAY, then MODE_LIST will be used.

Parameters:
arrayMode - array mode for conversion

setClassMap

public void setClassMap(java.util.Map classMap)
Sets the current attribute/Class Map

Parameters:
classMap - a Map of classes, every key identifies a property or a regexp

setCycleDetectionStrategy

public void setCycleDetectionStrategy(CycleDetectionStrategy cycleDetectionStrategy)
Sets a CycleDetectionStrategy to use.
Will set default value (CycleDetectionStrategy.STRICT) if null.


setExcludes

public void setExcludes(java.lang.String[] excludes)
Sets the excludes to use.
Will set default value ([]) if null.


setHandleJettisonEmptyElement

public void setHandleJettisonEmptyElement(boolean handleJettisonEmptyElement)
Activate/Deactive handling this jettison convention when converting to Java.
Jettison states that "" (empty string) can be assigned to empty elements (objects), which clearly violates the JSON spec.


setHandleJettisonSingleElementArray

public void setHandleJettisonSingleElementArray(boolean handleJettisonSingleElementArray)
Activate/Deactive handling this jettison convention when converting to Java.
* Jettison states the following JSON {'media':{'title':'hello'}} can be set as a single element JSONArray (media is the array).


setIgnoreDefaultExcludes

public void setIgnoreDefaultExcludes(boolean ignoreDefaultExcludes)
Sets if default ecludes would be skipped when building.


setIgnoreTransientFields

public void setIgnoreTransientFields(boolean ignoreTransientFields)
Sets if transient fields would be skipped when building.


setJavaIdentifierTransformer

public void setJavaIdentifierTransformer(JavaIdentifierTransformer javaIdentifierTransformer)
Sets the JavaIdentifierTransformer to use.
Will set default value (JavaIdentifierTransformer.NOOP) if null.


setJavaPropertyFilter

public void setJavaPropertyFilter(PropertyFilter javaPropertyFilter)
Sets a property filter used when serializing to Java.

Parameters:
javaPropertyFilter - the property filter

setJsonBeanProcessorMatcher

public void setJsonBeanProcessorMatcher(JsonBeanProcessorMatcher jsonBeanProcessorMatcher)
Sets a JsonBeanProcessorMatcher to use.
Will set default value (JsonBeanProcessorMatcher.STRICT) if null.


setJsonPropertyFilter

public void setJsonPropertyFilter(PropertyFilter jsonPropertyFilter)
Sets a property filter used when serializing to JSON.

Parameters:
jsonPropertyFilter - the property filter

setNewBeanInstanceStrategy

public void setNewBeanInstanceStrategy(NewBeanInstanceStrategy newBeanInstanceStrategy)
Sets the NewBeanInstanceStrategy to use.
Will set default value (NewBeanInstanceStrategy.DEFAULT) if null.


setRootClass

public void setRootClass(java.lang.Class rootClass)
Sets the current root Class

Parameters:
rootClass - the target class for conversion

setSkipJavaIdentifierTransformationInMapKeys

public void setSkipJavaIdentifierTransformationInMapKeys(boolean skipJavaIdentifierTransformationInMapKeys)
Sets if transient fields of beans would be skipped when building.


unregisterJsonBeanProcessor

public void unregisterJsonBeanProcessor(java.lang.Class target)
Removes a JsonBeanProcessor.

Parameters:
target - a class used for searching a JsonBeanProcessor.

unregisterJsonValueProcessor

public void unregisterJsonValueProcessor(java.lang.Class propertyType)
Removes a JsonValueProcessor.

Parameters:
propertyType - a class used for searching a JsonValueProcessor.

unregisterJsonValueProcessor

public void unregisterJsonValueProcessor(java.lang.Class beanClass,
                                         java.lang.Class propertyType)
Removes a JsonValueProcessor.

Parameters:
beanClass - the class to which the property may belong
propertyType - the type of the property

unregisterJsonValueProcessor

public void unregisterJsonValueProcessor(java.lang.Class beanClass,
                                         java.lang.String key)
Removes a JsonValueProcessor.

Parameters:
beanClass - the class to which the property may belong
key - the name of the property which may belong to the target class

unregisterJsonValueProcessor

public void unregisterJsonValueProcessor(java.lang.String key)
Removes a JsonValueProcessor.

Parameters:
key - the name of the property which may belong to the target class


Copyright © 2006-2012 Json-lib. All Rights Reserved.