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

Constructor Summary
DefaultJsonMapper()
           
 
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultJsonMapper

public DefaultJsonMapper()
Method Detail

toJavaList

public <T> List<T> toJavaList(String json,
                              Class<T> type)
                   throws FacebookJsonMappingException
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 visible 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.
Throws:
FacebookJsonMappingException - If an error occurs while mapping JSON to Java.
See Also:
JsonMapper.toJavaList(java.lang.String, java.lang.Class)

toJavaObject

public <T> T toJavaObject(String json,
                          Class<T> type)
               throws FacebookJsonMappingException
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 visible 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.
Throws:
FacebookJsonMappingException - If an error occurs while mapping JSON to Java.
See Also:
JsonMapper.toJavaObject(java.lang.String, java.lang.Class)

toJson

public String toJson(Object object)
              throws FacebookJsonMappingException
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.
Throws:
FacebookJsonMappingException - If an error occurs while mapping Java to JSON.
See Also:
JsonMapper.toJson(java.lang.Object)


RestFB version 1.5.3. Copyright © 2010 Mark Allen. All Rights Reserved.