net.sf.json
Class JsonConfig

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

public class JsonConfig
extends Object

Utility class that helps configuring the serialization process.

Author:
Andres Almiray

Method Summary
 void addJsonEventListener(JsonEventListener listener)
          Registers a listener for Json events.
 void clearJsonBeanProcessors()
          Removes all registered JsonBeanProcessors.
 void clearJsonEventListeners()
          Removes all registered listener for Json Events.
 void clearJsonValueProcessors()
          Removes all registered JsonValueProcessors.
 void disableEventTriggering()
          Disables event triggering when building.
 void enableEventTriggering()
          Enables event triggering when building.
 JsonBeanProcessor findJsonBeanProcessor(Class target)
          Finds a JsonBeanProcessor registered to the target class.
 JsonValueProcessor findJsonValueProcessor(Class propertyType)
          Finds a JsonValueProcessor registered to the target type.
 JsonValueProcessor findJsonValueProcessor(Class beanClass, Class propertyType, String key)
          Finds a JsonValueProcessor.
 JsonValueProcessor findJsonValueProcessor(Class propertyType, String key)
          Finds a JsonValueProcessor.
 CycleDetectionStrategy getCycleDetectionStrategy()
          Returns the configured CycleDetectionStrategy.
 String[] getExcludes()
          Returns the configured properties for exclusion.
static JsonConfig getInstance()
          Returns the singleton instance.
 JavaIdentifierTransformer getJavaIdentifierTransformer()
          Returns the configured JavaIdentifierTransformer.
 List getJsonEventListeners()
          Returns a list of registered listeners for Json events.
 Collection getMergedExcludes()
          Returns a set of default excludes with user-defined excludes.
 boolean isEventTriggeringEnabled()
          Returns true if event triggering is enabled during building.
 boolean isIgnoreDefaultExcludes()
          Returns true if default excludes will not be used.
 boolean isIgnoreTransientFields()
          Returns true if transient fields of a bean will be ignored.
 boolean isSkipJavaIdentifierTransformationInMapKeys()
          Returns true if map keys will not be transformed.
 void registerJsonBeanProcessor(Class target, JsonBeanProcessor jsonBeanProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(Class beanClass, Class propertyType, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(Class propertyType, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(Class beanClass, String key, JsonValueProcessor jsonValueProcessor)
          Registers a JsonValueProcessor.
 void registerJsonValueProcessor(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 setCycleDetectionStrategy(CycleDetectionStrategy cycleDetectionStrategy)
          Sets a CycleDetectionStrategy to use.
 void setExcludes(String[] excludes)
          Sets the excludes to use.
 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.
 void setSkipJavaIdentifierTransformationInMapKeys(boolean skipJavaIdentifierTransformationInMapKeys)
          Sets if transient fields of beans would be skipped when building.
 void unregisterJsonBeanProcessor(Class target)
          Removes a JsonBeanProcessor.
 void unregisterJsonValueProcessor(Class propertyType)
          Removes a JsonValueProcessor.
 void unregisterJsonValueProcessor(Class beanClass, Class propertyType)
          Removes a JsonValueProcessor.
 void unregisterJsonValueProcessor(Class beanClass, String key)
          Removes a JsonValueProcessor.
 void unregisterJsonValueProcessor(String key)
          Removes a JsonValueProcessor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static JsonConfig getInstance()
Returns the singleton instance.


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.


disableEventTriggering

public void disableEventTriggering()
Disables event triggering when building.


enableEventTriggering

public void enableEventTriggering()
Enables event triggering when building.


findJsonBeanProcessor

public JsonBeanProcessor findJsonBeanProcessor(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(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(Class beanClass,
                                                 Class propertyType,
                                                 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(Class propertyType,
                                                 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

getCycleDetectionStrategy

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


getExcludes

public 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


getJsonEventListeners

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


getMergedExcludes

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


isEventTriggeringEnabled

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


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(Class target,
                                      JsonBeanProcessor jsonBeanProcessor)
Registers a JsonValueProcessor.

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

registerJsonValueProcessor

public void registerJsonValueProcessor(Class beanClass,
                                       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(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(Class beanClass,
                                       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(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.


setCycleDetectionStrategy

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


setExcludes

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


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.


setSkipJavaIdentifierTransformationInMapKeys

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


unregisterJsonBeanProcessor

public void unregisterJsonBeanProcessor(Class target)
Removes a JsonBeanProcessor.

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

unregisterJsonValueProcessor

public void unregisterJsonValueProcessor(Class propertyType)
Removes a JsonValueProcessor.

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

unregisterJsonValueProcessor

public void unregisterJsonValueProcessor(Class beanClass,
                                         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(Class beanClass,
                                         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(String key)
Removes a JsonValueProcessor.

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