com.restfb
Class DefaultJsonMapper

java.lang.Object
  extended by com.restfb.DefaultJsonMapper
All Implemented Interfaces:
JsonMapper

public class DefaultJsonMapper
extends Object
implements JsonMapper

Default implementation of a JSON-to-Java mapper.

Author:
Mark Allen

Nested Class Summary
static interface DefaultJsonMapper.JsonMappingErrorHandler
          Callback interface which allows client code to specify how JSON mapping errors should be handled.
 
Constructor Summary
DefaultJsonMapper()
          Creates a JSON mapper which will throw FacebookJsonMappingException whenever an error occurs when mapping JSON data to Java objects.
DefaultJsonMapper(DefaultJsonMapper.JsonMappingErrorHandler jsonMappingErrorHandler)
          Creates a JSON mapper which delegates to the provided jsonMappingErrorHandler for handling mapping errors.
 
Method Summary
<T> List<T>
toJavaList(String json, Class<T> type)
          Given a JSON string, create and return a new instance of a corresponding Java List which contains elements of type type.
<T> T
toJavaObject(String json, Class<T> type)
          Given a JSON string, create and return a new instance of a corresponding Java object of type type.
 String toJson(Object object)
          Given a Java object, create and return a JSON string that represents it.
 String toJson(Object object, boolean ignoreNullValuedProperties)
          Given a Java object, create and return a JSON string that represents it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultJsonMapper

public DefaultJsonMapper()
Creates a JSON mapper which will throw FacebookJsonMappingException whenever an error occurs when mapping JSON data to Java objects.


DefaultJsonMapper

public DefaultJsonMapper(DefaultJsonMapper.JsonMappingErrorHandler jsonMappingErrorHandler)
Creates a JSON mapper which delegates to the provided jsonMappingErrorHandler for handling mapping errors.

Parameters:
jsonMappingErrorHandler - The JSON mapping error handler to use.
Throws:
IllegalArgumentException - If jsonMappingErrorHandler is null.
Since:
1.6.2
Method Detail

toJavaList

public <T> List<T> toJavaList(String json,
                              Class<T> type)
Description copied from interface: JsonMapper
Given a JSON string, create and return a new instance of a corresponding Java List which contains elements of type type.

The Java type must have a no-argument constructor.

Specified by:
toJavaList in interface JsonMapper
Type Parameters:
T - Java type to map to for each element of the list.
Parameters:
json - The JSON to be mapped to a Java type.
type - Java type token.
Returns:
A Java object (of type List which contains elements of type type) representation of the JSON input.
See Also:
JsonMapper.toJavaList(java.lang.String, java.lang.Class)

toJavaObject

public <T> T toJavaObject(String json,
                          Class<T> type)
Description copied from interface: JsonMapper
Given a JSON string, create and return a new instance of a corresponding Java object of type type.

The Java type must have a no-argument constructor.

Specified by:
toJavaObject in interface JsonMapper
Type Parameters:
T - Java type to map to.
Parameters:
json - The JSON to be mapped to a Java type.
type - Java type token.
Returns:
A Java object (of type type) representation of the JSON input.
See Also:
JsonMapper.toJavaObject(java.lang.String, java.lang.Class)

toJson

public String toJson(Object object)
Description copied from interface: JsonMapper
Given a Java object, create and return a JSON string that represents it.

The object's properties will be traversed recursively, allowing for arbitrarily complex JSON generation.

Specified by:
toJson in interface JsonMapper
Parameters:
object - The Java object to map to JSON. Can be a Javabean, List, or Map.
Returns:
A JSON string.
See Also:
JsonMapper.toJson(java.lang.Object)

toJson

public String toJson(Object object,
                     boolean ignoreNullValuedProperties)
Description copied from interface: JsonMapper
Given a Java object, create and return a JSON string that represents it.

The object's properties will be traversed recursively, allowing for arbitrarily complex JSON generation.

Specified by:
toJson in interface JsonMapper
Parameters:
object - The Java object to map to JSON. Can be a Javabean, List, or Map.
ignoreNullValuedProperties - If true, no Javabean properties with null values will be included in the generated JSON.
Returns:
A JSON string.
See Also:
JsonMapper.toJson(java.lang.Object, boolean)


RestFB 1.6.8. Copyright © 2010-2011 Mark Allen. All Rights Reserved.