org.sr.common.transformer.json
Class JSTransformer

java.lang.Object
  extended by org.sr.common.transformer.json.JSTransformer
All Implemented Interfaces:
ITransformer<java.lang.Object>, IJSTransformer

public final class JSTransformer
extends java.lang.Object
implements IJSTransformer

This class is designed to be a generic JSON transformer which covers all Java types. The class contains references to all type converters and uses them in it's operations. The project covers all java types from primitives to complex beans. It's quite easy to add your own transformer classes by using registerTransformer method of this class to improve transformation performance.

Author:
Serhat Dirik

Field Summary
 
Fields inherited from interface org.sr.common.transformer.json.IJSTransformer
ARRAY_ATTRIBUTE, ARRAY_CLASS, JSNULL_CLASS_IDENTIFIER, JSNULL_VALUE, LIST_ATTRIBUTE, MAP_ATTRIBUTE, MAPITEM_PREFIX, MAPKEY_ATTRIBUTE, MAPVALUE_ATTRIBUTE, SET_ATTRIBUTE, TIME_ATTRIBUTE, TIMEZONE_ATTRIBUTE
 
Fields inherited from interface org.sr.common.transformer.ITransformer
CLASS_HINT_ATTRIBUTE, VALUE_ATTRIBUTE
 
Constructor Summary
JSTransformer()
           
 
Method Summary
 java.util.List<java.lang.Class<?>> findConvertibles()
          Gives convertible java types
 boolean isConvertible(java.lang.Class<?> clazz)
          tells if the given class is convertible by the implementation
 boolean isConvertible(java.lang.String className)
          tells if the given class is convertible by the implementation
static void registerTransformer(java.lang.Class<? extends IJSTransformer> clazz)
           
 java.lang.Object toJava(java.lang.Class<?> clazz, java.lang.Object obj)
          Transforms from target type to Java
 java.lang.Object toJava(java.lang.Object obj)
          Transforms from target type to Java
 java.lang.Object toTargetType(java.lang.Object o)
          Converts java object to targetted type
 java.lang.Object toTargetType(java.lang.Object o, ObjectReferenceMap referenceMap)
          Converts java object to targetted type
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSTransformer

public JSTransformer()
Method Detail

registerTransformer

public static final void registerTransformer(java.lang.Class<? extends IJSTransformer> clazz)

toJava

public java.lang.Object toJava(java.lang.Object obj)
                        throws TransformationException,
                               TransformationNotSupportedException
Description copied from interface: ITransformer
Transforms from target type to Java

Specified by:
toJava in interface ITransformer<java.lang.Object>
Parameters:
obj - source object
Returns:
java object
Throws:
TransformationException
TransformationNotSupportedException

toJava

public java.lang.Object toJava(java.lang.Class<?> clazz,
                               java.lang.Object obj)
                        throws TransformationException,
                               TransformationNotSupportedException
Description copied from interface: ITransformer
Transforms from target type to Java

Specified by:
toJava in interface ITransformer<java.lang.Object>
Parameters:
clazz - to be transformed java class
obj - source object
Returns:
java object
Throws:
TransformationException
TransformationNotSupportedException

toTargetType

public java.lang.Object toTargetType(java.lang.Object o)
                              throws TransformationException,
                                     TransformationNotSupportedException
Description copied from interface: ITransformer
Converts java object to targetted type

Specified by:
toTargetType in interface ITransformer<java.lang.Object>
Parameters:
o - source java object
Returns:
targeted type
Throws:
TransformationException
TransformationNotSupportedException

toTargetType

public java.lang.Object toTargetType(java.lang.Object o,
                                     ObjectReferenceMap referenceMap)
                              throws TransformationException,
                                     TransformationNotSupportedException
Description copied from interface: ITransformer
Converts java object to targetted type

Specified by:
toTargetType in interface ITransformer<java.lang.Object>
Parameters:
o - source java object
referenceMap - this parameters usually created by highest level transformer to control cyclic dependencies
Returns:
targeted type
Throws:
TransformationException
TransformationNotSupportedException

findConvertibles

public java.util.List<java.lang.Class<?>> findConvertibles()
Description copied from interface: ITransformer
Gives convertible java types

Specified by:
findConvertibles in interface ITransformer<java.lang.Object>
Returns:
list of convertible classes

isConvertible

public boolean isConvertible(java.lang.String className)
Description copied from interface: ITransformer
tells if the given class is convertible by the implementation

Specified by:
isConvertible in interface ITransformer<java.lang.Object>
Returns:
true if convertible

isConvertible

public boolean isConvertible(java.lang.Class<?> clazz)
Description copied from interface: ITransformer
tells if the given class is convertible by the implementation

Specified by:
isConvertible in interface ITransformer<java.lang.Object>
Returns:
true if convertible