Package com.restfb
Klasse DefaultJsonMapper
java.lang.Object
com.restfb.DefaultJsonMapper
- Alle implementierten Schnittstellen:
JsonMapper
Default implementation of a JSON-to-Java mapper.
- Autor:
- Mark Allen
-
Verschachtelte Klassen - Übersicht
Von Schnittstelle geerbte verschachtelte Klassen/Schnittstellen com.restfb.JsonMapper
JsonMapper.JsonMappingCompleted
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungCreates a JSON mapper which will throwFacebookJsonMappingException
whenever an error occurs when mapping JSON data to Java objects. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungfacebookFieldNamesWithMultipleMappings
(List<ReflectionUtils.FieldWithAnnotation<Facebook>> fieldsWithAnnotation) Finds any Facebook JSON fields that are mapped to more than 1 Java field.protected String
getFacebookFieldName
(ReflectionUtils.FieldWithAnnotation<Facebook> fieldWithAnnotation) For a Java field annotated with theFacebook
annotation, figure out what the corresponding Facebook JSON field name to map to it is.protected void
Finds and invokes methods onobject
that are annotated with the@JsonMappingCompleted
annotation.protected void
logMultipleMappingFailedForField
(String facebookFieldName, ReflectionUtils.FieldWithAnnotation<Facebook> fieldWithAnnotation, String json) Dumps out a log message when one of a multiple-mapped Facebook field name JSON-to-Java mapping operation fails.void
setFacebookClient
(FacebookClient facebookClient) adds aFacebookClient
implementation to the mapper.<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
.protected Object
toJavaType
(ReflectionUtils.FieldWithAnnotation<Facebook> fieldWithAnnotation, JsonObject jsonObject, String facebookFieldName) Extracts JSON data for a field according to itsFacebook
annotation and returns it converted to the proper Java type.Given a Javaobject
, create and return a JSON string that represents it.Given a Javaobject
, create and return a JSON string that represents it.protected JsonValue
toJsonInternal
(Object object, boolean ignoreNullValuedProperties) Recursively marshal the givenobject
to JSON.protected <T> T
toPrimitiveJavaType
(String json, Class<T> type) Given ajson
value of something likeMyValue
or123
, return a representation of that value of typetype
.
-
Konstruktordetails
-
DefaultJsonMapper
public DefaultJsonMapper()Creates a JSON mapper which will throwFacebookJsonMappingException
whenever an error occurs when mapping JSON data to Java objects.
-
-
Methodendetails
-
setFacebookClient
Beschreibung aus Schnittstelle kopiert:JsonMapper
adds aFacebookClient
implementation to the mapper. This is especially useful for mapping json to Connection objects that need the client itself.- Angegeben von:
setFacebookClient
in SchnittstelleJsonMapper
- Parameter:
facebookClient
- that is used for Connection objects
-
toJavaList
Beschreibung aus Schnittstelle kopiert:JsonMapper
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.- Angegeben von:
toJavaList
in SchnittstelleJsonMapper
- Typparameter:
T
- Java type to map to for each element of the list.- Parameter:
json
- The JSON to be mapped to a Java type.type
- Java type token.- Gibt zurück:
- A Java object (of type
List
which contains elements of typetype
) representation of the JSON input.
-
toJavaObject
Beschreibung aus Schnittstelle kopiert:JsonMapper
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.- Angegeben von:
toJavaObject
in SchnittstelleJsonMapper
- Typparameter:
T
- Java type to map to.- Parameter:
json
- The JSON to be mapped to a Java type.type
- Java type token.- Gibt zurück:
- A Java object (of type
type
) representation of the JSON input.
-
invokeJsonMappingCompletedMethods
protected void invokeJsonMappingCompletedMethods(Object object) throws IllegalAccessException, InvocationTargetException Finds and invokes methods onobject
that are annotated with the@JsonMappingCompleted
annotation.This will even work on
private
methods.- Parameter:
object
- The object on which to invoke the method.- Löst aus:
IllegalAccessException
- If unable to invoke the method.InvocationTargetException
- If unable to invoke the method.
-
logMultipleMappingFailedForField
protected void logMultipleMappingFailedForField(String facebookFieldName, ReflectionUtils.FieldWithAnnotation<Facebook> fieldWithAnnotation, String json) Dumps out a log message when one of a multiple-mapped Facebook field name JSON-to-Java mapping operation fails.- Parameter:
facebookFieldName
- The Facebook field name.fieldWithAnnotation
- The Java field to map to and its annotation.json
- The JSON that failed to map to the Java field.
-
getFacebookFieldName
protected String getFacebookFieldName(ReflectionUtils.FieldWithAnnotation<Facebook> fieldWithAnnotation) For a Java field annotated with theFacebook
annotation, figure out what the corresponding Facebook JSON field name to map to it is.- Parameter:
fieldWithAnnotation
- A Java field annotated with theFacebook
annotation.- Gibt zurück:
- The Facebook JSON field name that should be mapped to this Java field.
-
facebookFieldNamesWithMultipleMappings
protected Set<String> facebookFieldNamesWithMultipleMappings(List<ReflectionUtils.FieldWithAnnotation<Facebook>> fieldsWithAnnotation) Finds any Facebook JSON fields that are mapped to more than 1 Java field.- Parameter:
fieldsWithAnnotation
- Java fields annotated with theFacebook
annotation.- Gibt zurück:
- Any Facebook JSON fields that are mapped to more than 1 Java field.
-
toJson
Beschreibung aus Schnittstelle kopiert:JsonMapper
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.- Angegeben von:
toJson
in SchnittstelleJsonMapper
- Parameter:
object
- The Java object to map to JSON. Can be a Javabean,List
, orMap
.- Gibt zurück:
- A JSON string.
-
toJson
Beschreibung aus Schnittstelle kopiert:JsonMapper
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.- Angegeben von:
toJson
in SchnittstelleJsonMapper
- Parameter:
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.- Gibt zurück:
- A JSON string.
-
toJsonInternal
Recursively marshal the givenobject
to JSON.Used by
toJson(Object)
.- Parameter:
object
- The object to marshal.ignoreNullValuedProperties
- If this istrue
, no Javabean properties withnull
values will be included in the generated JSON.- Gibt zurück:
- JSON representation of the given
object
. - Löst aus:
FacebookJsonMappingException
- If an error occurs while marshaling to JSON.
-
toPrimitiveJavaType
Given ajson
value of something likeMyValue
or123
, return a representation of that value of typetype
.This is to support non-legal JSON served up by Facebook for API calls like
Friends.get
(example result:[222333,1240079]
).- Typparameter:
T
- The Java type to map to.- Parameter:
json
- The non-legal JSON to map to the Java type.type
- Type token.- Gibt zurück:
- Java representation of
json
. - Löst aus:
FacebookJsonMappingException
- If an error occurs while mapping JSON to Java.
-
toJavaType
protected Object toJavaType(ReflectionUtils.FieldWithAnnotation<Facebook> fieldWithAnnotation, JsonObject jsonObject, String facebookFieldName) Extracts JSON data for a field according to itsFacebook
annotation and returns it converted to the proper Java type.- Parameter:
fieldWithAnnotation
- The field/annotation pair which specifies what Java type to convert to.jsonObject
- "Raw" JSON object to pull data from.facebookFieldName
- Specifies what JSON field to pull "raw" data from.- Gibt zurück:
- A
- Löst aus:
ParseException
- If an error occurs while mapping JSON to Java.FacebookJsonMappingException
- If an error occurs while mapping JSON to Java.
-