Package com.restfb
Interface JsonMapper
-
- All Known Implementing Classes:
DefaultJsonMapper
public interface JsonMapper
Specifies how a Facebook JSON-to-Java (and vice-versa) mapper must operate.Note that implementors must be able to handle illegal JSON in
toJavaObject(String, Class)
andtoJavaList(String, Class)
in order to correctly process Facebook responses. For example, theUsers.getLoggedInUser
Legacy API call returns a value like1240077
, which is not valid JSON.- Author:
- Mark Allen
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
JsonMapper.JsonMappingCompleted
If you apply this annotation to a method of a type mapped byJsonMapper
, it will be called after the mapping operation has been completed.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> List<T>
toJavaList(String json, Class<T> type)
Given a JSON string, create and return a new instance of a corresponding JavaList
which contains elements of typetype
.<T> T
toJavaObject(String json, Class<T> type)
Given a JSON string, create and return a new instance of a corresponding Java object of typetype
.String
toJson(Object object)
Given a Javaobject
, create and return a JSON string that represents it.String
toJson(Object object, boolean ignoreNullValuedProperties)
Given a Javaobject
, create and return a JSON string that represents it.
-
-
-
Method Detail
-
toJavaObject
<T> T toJavaObject(String json, Class<T> type)
Given a JSON string, create and return a new instance of a corresponding Java object of typetype
.The Java
type
must have a no-argument constructor.- 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.
-
toJavaList
<T> List<T> toJavaList(String json, Class<T> type)
Given a JSON string, create and return a new instance of a corresponding JavaList
which contains elements of typetype
.The Java
type
must have a no-argument constructor.- 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 typetype
) representation of the JSON input. - Throws:
FacebookJsonMappingException
- If an error occurs while mapping JSON to Java.
-
toJson
String toJson(Object object)
Given a Javaobject
, create and return a JSON string that represents it.The
object
's properties will be traversed recursively, allowing for arbitrarily complex JSON generation.- Parameters:
object
- The Java object to map to JSON. Can be a Javabean,List
, orMap
.- Returns:
- A JSON string.
- Throws:
FacebookJsonMappingException
- If an error occurs while mapping Java to JSON.- Since:
- 1.4
-
toJson
String toJson(Object object, boolean ignoreNullValuedProperties)
Given a Javaobject
, create and return a JSON string that represents it.The
object
's properties will be traversed recursively, allowing for arbitrarily complex JSON generation.- Parameters:
object
- The Java object to map to JSON. Can be a Javabean,List
, orMap
.ignoreNullValuedProperties
- Iftrue
, no Javabean properties withnull
values will be included in the generated JSON.- Returns:
- A JSON string.
- Throws:
FacebookJsonMappingException
- If an error occurs while mapping Java to JSON.- Since:
- 1.6.5
-
-