com.supermap.services.rest.encoders

Class JsonEncoder

  • All Implemented Interfaces:
    javax.ws.rs.ext.MessageBodyWriter
    Direct Known Subclasses:
    GeoJSONEncoder, JsonpEncoder, RJsonEncoder


    @Provider
    public class JsonEncoder
    extends Encoder
    implements javax.ws.rs.ext.MessageBodyWriter
    

    ${services_rest_encoders_JsonEncoder_Title}

    ${services_rest_encoders_JsonEncoder_Description}

    • Constructor Summary

      Constructors 
      Constructor and Description
      JsonEncoder()
      ${services_rest_encoders_JsonEncoder_constructor_JsonEncoder_Title}
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      protected java.util.List<MediaType> createSupportedMediaTypes()
      ${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_Title}
      long getSize(java.lang.Object o, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Determines the length of the object to be written after serialization.
      protected boolean isindent()
      Whether to generate a string in an indented format.
      boolean isWriteable(java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Determines whether the present expression supports the representation of the specified media type.
      protected java.lang.Object toFormatedObject(java.lang.Object obj)
      Converts an object to an object of type JSONObject.
      protected java.lang.String toFormatedString(java.lang.Object resultObj)
      Will be standard objects such as: JSONObject, JSONArray converted to meet certain specifications of the string, such as JSON, JSONP and so on.
      Representation toRepresentation(MediaType mediaType, java.lang.Object resourceObj)
      ${services_rest_encoders_JsonEncoder_method_toRepresentation_Title}
      void writeTo(java.lang.Object o, java.lang.Class type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap httpHeaders, java.io.OutputStream entityStream)
      Generates an HTTP response for the specified media type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonEncoder

        public JsonEncoder()
        

        ${services_rest_encoders_JsonEncoder_constructor_JsonEncoder_Title}

        ${services_rest_encoders_JsonEncoder_constructor_JsonEncoder_Description}

    • Method Detail

      • isWriteable

        public boolean isWriteable(java.lang.Class type,
                          java.lang.reflect.Type genericType,
                          java.lang.annotation.Annotation[] annotations,
                          javax.ws.rs.core.MediaType mediaType)
        

        Determines whether the present expression supports the representation of the specified media type.

        Specified by:
        isWriteable in interface javax.ws.rs.ext.MessageBodyWriter
        Parameters:
        type - The type of object to generate the expression.
        genericType - the specified object type.
        annotations - annotation array, the resource has these annotation methods to return to the object to be written.
        mediaType - The media type of the expected response.
        Returns:
        Returns true if this expression generator supports the specified media type, false otherwise.
      • getSize

        public long getSize(java.lang.Object o,
                   java.lang.Class type,
                   java.lang.reflect.Type genericType,
                   java.lang.annotation.Annotation[] annotations,
                   javax.ws.rs.core.MediaType mediaType)
        

        Determines the length of the object to be written after serialization. Is called before the HTTP response is generated.

        Specified by:
        getSize in interface javax.ws.rs.ext.MessageBodyWriter
        Parameters:
        o - To generate an expression object.
        type - The Java class that corresponds to the object to be generated.
        genericType - To generate an expression object type.
        annotations - annotation array, the resource has these annotation methods to return to the object to be written.
        mediaType - The media type of the HTTP response.
        Returns:
        the length of the object to be written.
      • writeTo

        public void writeTo(java.lang.Object o,
                   java.lang.Class type,
                   java.lang.reflect.Type genericType,
                   java.lang.annotation.Annotation[] annotations,
                   javax.ws.rs.core.MediaType mediaType,
                   javax.ws.rs.core.MultivaluedMap httpHeaders,
                   java.io.OutputStream entityStream)
                     throws java.io.IOException,
                            javax.ws.rs.WebApplicationException
        

        Generates an HTTP response for the specified media type.

        Specified by:
        writeTo in interface javax.ws.rs.ext.MessageBodyWriter
        Parameters:
        o - To generate an expression object.
        type - The Java class that corresponds to the object to be generated.
        genericType - To generate an expression object type.
        annotations - annotation array, the resource has these annotation methods to return to the object to be written.
        mediaType - HTTP The media type of the response.
        httpHeaders - HTTP Response to the message header.
        entityStream - HTTP response.
        Throws:
        java.io.IOException - When the read and write process is wrong.
        javax.ws.rs.WebApplicationException - When the HTTP response fails.
      • createSupportedMediaTypes

        protected java.util.List<MediaType> createSupportedMediaTypes()
        

        ${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_Title}

        ${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_Description}

        Specified by:
        createSupportedMediaTypes in class Encoder
        Returns:
        ${services_rest_encoders_JsonEncoder_method_createSupportedMediaTypes_return}
      • toRepresentation

        public Representation toRepresentation(MediaType mediaType,
                                      java.lang.Object resourceObj)
        

        ${services_rest_encoders_JsonEncoder_method_toRepresentation_Title}

        ${services_rest_encoders_JsonEncoder_method_toRepresentation_Description}

        Specified by:
        toRepresentation in class Encoder
        Parameters:
        mediaType - ${services_rest_encoders_JsonEncoder_method_toRepresentation_param_mediaType}
        resourceObj - ${services_rest_encoders_JsonEncoder_method_toRepresentation_param_resourceObj}
        Returns:
        ${services_rest_encoders_JsonEncoder_method_toRepresentation_return}
      • toFormatedObject

        protected java.lang.Object toFormatedObject(java.lang.Object obj)
        

        Converts an object to an object of type JSONObject. If the incoming parameter is of the base type, it is not converted and returns null.

        Parameters:
        obj - The Java object to be converted.
        Returns:
        converted JSONObject object.
      • toFormatedString

        protected java.lang.String toFormatedString(java.lang.Object resultObj)
        

        Will be standard objects such as: JSONObject, JSONArray converted to meet certain specifications of the string, such as JSON, JSONP and so on.

        Parameters:
        resultObj - The object to be converted.
        Returns:
        Result string.
      • isindent

        protected boolean isindent()
        

        Whether to generate a string in an indented format.

        Returns:
        Returns true if the string is generated in an indented format, false otherwise.