Package com.restfb

Class DefaultJsonMapper

    • 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.
      • 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.
      • 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.
        Parameters:
        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 the Facebook annotation, figure out what the corresponding Facebook JSON field name to map to it is.
        Parameters:
        fieldWithAnnotation - A Java field annotated with the Facebook annotation.
        Returns:
        The Facebook JSON field name that should be mapped to this Java field.
      • 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.
      • 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.
      • toJsonInternal

        protected JsonValue toJsonInternal​(Object object,
                                           boolean ignoreNullValuedProperties)
        Recursively marshal the given object to JSON.

        Used by toJson(Object).

        Parameters:
        object - The object to marshal.
        ignoreNullValuedProperties - If this is true, no Javabean properties with null values will be included in the generated JSON.
        Returns:
        JSON representation of the given object.
        Throws:
        FacebookJsonMappingException - If an error occurs while marshaling to JSON.
      • toPrimitiveJavaType

        protected <T> T toPrimitiveJavaType​(String json,
                                            Class<T> type)
        Given a json value of something like MyValue or 123 , return a representation of that value of type type.

        This is to support non-legal JSON served up by Facebook for API calls like Friends.get (example result: [222333,1240079]).

        Type Parameters:
        T - The Java type to map to.
        Parameters:
        json - The non-legal JSON to map to the Java type.
        type - Type token.
        Returns:
        Java representation of json.
        Throws:
        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 its Facebook annotation and returns it converted to the proper Java type.
        Parameters:
        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.
        Returns:
        A
        Throws:
        ParseException - If an error occurs while mapping JSON to Java.
        FacebookJsonMappingException - If an error occurs while mapping JSON to Java.