net.sourceforge.javajson.converter
Class Converter

java.lang.Object
  extended by net.sourceforge.javajson.converter.Converter

public class Converter
extends Object

Converts java objects to json based on bean-style fields and classes/interfaces (to filter)

Author:
miguel de anda

Field Summary
static Converter instance
           
protected  Logger log
           
 
Method Summary
 Object fromJson(JsonObject json)
           
static Converter getInstance()
           
 JsonObject toJson(Object o)
          Convenience method for converting objects without a predefined mapper.
 JsonObject toJson(Object o, boolean flat)
          Convenience method for converting objects without a predefined mapper.
 JsonObject toJson(Object o, Class cls)
          Convenience method for converting objects without a predefined mapper.
 JsonArray toJsonArray(Collection c)
          Convenience method for converting objects without a predefined mapper.
 JsonArray toJsonArray(Collection c, boolean flat)
          Convenience method for converting objects without a predefined mapper.
 JsonArray toJsonArray(Collection c, Class cls)
          Convenience method for converting collections without a predefined mapper.
 JsonArray toJsonArray(Collection c, Class cls, boolean flat)
          Convenience method for converting collections without a predefined mapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Logger log

instance

public static final Converter instance
Method Detail

getInstance

public static Converter getInstance()

fromJson

public Object fromJson(JsonObject json)
                throws ClassNotFoundException,
                       InstantiationException,
                       IllegalAccessException,
                       IllegalArgumentException,
                       InvocationTargetException
Throws:
ClassNotFoundException
InstantiationException
IllegalAccessException
IllegalArgumentException
InvocationTargetException

toJson

public JsonObject toJson(Object o)
                  throws SecurityException,
                         IllegalArgumentException,
                         NoSuchMethodException,
                         IllegalAccessException,
                         InvocationTargetException
Convenience method for converting objects without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will then do the conversion on that object as well. If the return type is a Collection, it will be converted to a JsonArray

Parameters:
o -
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

toJson

public JsonObject toJson(Object o,
                         boolean flat)
                  throws SecurityException,
                         IllegalArgumentException,
                         NoSuchMethodException,
                         IllegalAccessException,
                         InvocationTargetException
Convenience method for converting objects without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will then do the conversion on that object as well. If the return type is a Collection, it will be converted to a JsonArray

Parameters:
o -
flat - Don't look at non basic fields (numbers, strings, dates, boolean)
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

toJson

public JsonObject toJson(Object o,
                         Class cls)
                  throws SecurityException,
                         IllegalArgumentException,
                         NoSuchMethodException,
                         IllegalAccessException,
                         InvocationTargetException
Convenience method for converting objects without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will be skipped.

Parameters:
o -
cls - The class to read the fields from
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

toJsonArray

public JsonArray toJsonArray(Collection c)
                      throws SecurityException,
                             IllegalArgumentException,
                             NoSuchMethodException,
                             IllegalAccessException,
                             InvocationTargetException
Convenience method for converting objects without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will then do the conversion on that object as well. If the return type is a Collection, it will be converted to a JsonArray

Parameters:
o -
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

toJsonArray

public JsonArray toJsonArray(Collection c,
                             boolean flat)
                      throws SecurityException,
                             IllegalArgumentException,
                             NoSuchMethodException,
                             IllegalAccessException,
                             InvocationTargetException
Convenience method for converting objects without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will then do the conversion on that object as well. If the return type is a Collection, it will be converted to a JsonArray

Parameters:
o -
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

toJsonArray

public JsonArray toJsonArray(Collection c,
                             Class cls)
                      throws SecurityException,
                             IllegalArgumentException,
                             NoSuchMethodException,
                             IllegalAccessException,
                             InvocationTargetException
Convenience method for converting collections without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will be skipped.

Parameters:
o -
cls - The class to read the fields from
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException

toJsonArray

public JsonArray toJsonArray(Collection c,
                             Class cls,
                             boolean flat)
                      throws SecurityException,
                             IllegalArgumentException,
                             NoSuchMethodException,
                             IllegalAccessException,
                             InvocationTargetException
Convenience method for converting collections without a predefined mapper. This method does not allow objects to be filtered in any way and will inspect every public getter and return its value, if the value is not a Number, String or Date, it will be skipped.

Parameters:
o -
cls - The class to read the fields from
Returns:
Throws:
SecurityException
IllegalArgumentException
NoSuchMethodException
IllegalAccessException
InvocationTargetException