com.supermap.services.rest.decoders

Class JsonDecoder

  • All Implemented Interfaces:
    javax.ws.rs.ext.MessageBodyReader<java.lang.Object>
    Direct Known Subclasses:
    FlexRequestEntityDecoder


    @Provider
    public class JsonDecoder
    extends Decoder
    implements javax.ws.rs.ext.MessageBodyReader<java.lang.Object>
    

    ${services_rest_decoders_JsonDecoder_Title}

    ${services_rest_decoders_JsonDecoder_Description}

    • Constructor Summary

      Constructors 
      Constructor and Description
      JsonDecoder()
      The Constructor.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addResolvers(java.util.List<JsonDecoderResolver> resolvers)
      Sets the deserializer.
      void addTypeRestrict(java.lang.Class type, java.lang.String fieldName, JsonConverter.FieldInfo restrict)
      Adds a type definition that indicates a description of a field for a type The interface is mainly used to solve the deserialization of List, Set, Map and other types, the deserialization class does not know the type of collection elements.
      protected java.util.List<MediaType> createSupportedMediaTypes()
      ${services_rest_decoders_JsonDecoder_method_createSupportedMediaTypes_Title}
      boolean isReadable(java.lang.Class<?> arg0, java.lang.reflect.Type arg1, java.lang.annotation.Annotation[] arg2, javax.ws.rs.core.MediaType arg3)
      Determines whether the request body can be deserialized as a Java object.
      java.lang.Object readFrom(java.lang.Class<java.lang.Object> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> httpHeaders, java.io.InputStream entityStream)
      The request body is deserialized into Java objects.
      java.lang.Object toArray(JSONArray jsonArray, java.lang.Class arrayElementType)
      ${services_rest_decoders_JsonDecoder_method_toArrayByJson_Title}
      <T> java.util.List<T> toList(java.lang.String text, java.lang.Class<T> elementClass)
      ${services_rest_decoders_JsonDecoder_method_toList_Title}
      java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.String str, java.util.Map<java.lang.String,java.lang.Class> nameClassMapping)
      ${services_rest_decoders_JsonDecoder_method_toMap_Title}
      <T> T toObject(java.lang.String jsonStr, java.lang.Class<T> targetClass)
      ${services_rest_decoders_JsonDecoder_method_toObject_Title}
      java.util.Set toSet(java.lang.String text, java.lang.Class elementClass)
      ${services_rest_decoders_JsonDecoder_method_toSet_Title}
      • Methods inherited from class java.lang.Object

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

      • JsonDecoder

        public JsonDecoder()
        

        The Constructor.

    • Method Detail

      • toObject

        public <T> T toObject(java.lang.String jsonStr,
                     java.lang.Class<T> targetClass)
                   throws JSONException
        

        ${services_rest_decoders_JsonDecoder_method_toObject_Title}

        ${services_rest_decoders_JsonDecoder_method_toObject_Description}

        Specified by:
        toObject in class Decoder
        Parameters:
        jsonStr - ${services_rest_decoders_JsonDecoder_method_toObject_param_jsonStr}
        targetClass - ${services_rest_decoders_JsonDecoder_method_toObject_param_targetClass}
        Returns:
        ${services_rest_decoders_JsonDecoder_method_toObject_return}
        Throws:
        java.lang.IllegalArgumentException
        JSONException
      • toMap

        public java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.String str,
                                                             java.util.Map<java.lang.String,java.lang.Class> nameClassMapping)
        

        ${services_rest_decoders_JsonDecoder_method_toMap_Title}

        ${services_rest_decoders_JsonDecoder_method_toMap_Description}

        Specified by:
        toMap in class Decoder
        Parameters:
        str - ${services_rest_decoders_JsonDecoder_method_toMap_param_str}
        nameClassMapping - java.util.Map mapping set. Where the key is the field name and the value is the type of the field.
        Returns:
        ${services_rest_decoders_JsonDecoder_method_toMap_return}
      • toList

        public <T> java.util.List<T> toList(java.lang.String text,
                                   java.lang.Class<T> elementClass)
                                 throws JSONException
        

        ${services_rest_decoders_JsonDecoder_method_toList_Title}

        ${services_rest_decoders_JsonDecoder_method_toList_Description}

        Specified by:
        toList in class Decoder
        Parameters:
        text - ${services_rest_decoders_JsonDecoder_method_toList_param_text}
        elementClass - ${services_rest_decoders_JsonDecoder_method_toList_param_elementClass}
        Returns:
        ${services_rest_decoders_JsonDecoder_method_toList_return}
        Throws:
        JSONException - ${services_rest_decoders_JsonDecoder_method_toList_throws_Exception}
      • toSet

        public java.util.Set toSet(java.lang.String text,
                          java.lang.Class elementClass)
                            throws JSONException
        

        ${services_rest_decoders_JsonDecoder_method_toSet_Title}

        ${services_rest_decoders_JsonDecoder_method_toSet_Description}

        Specified by:
        toSet in class Decoder
        Parameters:
        text - ${services_rest_decoders_JsonDecoder_method_toSet_param_text}
        elementClass - ${services_rest_decoders_JsonDecoder_method_toSet_param_elementClass}
        Returns:
        ${services_rest_decoders_JsonDecoder_method_toSet_return}
        Throws:
        JSONException - ${services_rest_decoders_JsonDecoder_method_toSet_throws_Exception}
      • createSupportedMediaTypes

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

        ${services_rest_decoders_JsonDecoder_method_createSupportedMediaTypes_Title}

        ${services_rest_decoders_JsonDecoder_method_createSupportedMediaTypes_Description}

        Specified by:
        createSupportedMediaTypes in class Decoder
        Returns:
        ${services_rest_decoders_JsonDecoder_method_createSupportedMediaTypes_return}
      • toArray

        public java.lang.Object toArray(JSONArray jsonArray,
                               java.lang.Class arrayElementType)
                                 throws JSONException
        

        ${services_rest_decoders_JsonDecoder_method_toArrayByJson_Title}

        ${services_rest_decoders_JsonDecoder_method_toArrayByJson_Description}

        Parameters:
        jsonArray - ${services_rest_decoders_JsonDecoder_method_toArrayByJson_param_jsonArray}
        arrayElementType - ${services_rest_decoders_JsonDecoder_method_toArrayByJson_param_arrayElementType}
        Returns:
        ${services_rest_decoders_JsonDecoder_method_toArrayByJson_return}
        Throws:
        JSONException
      • addResolvers

        public void addResolvers(java.util.List<JsonDecoderResolver> resolvers)
        
        Sets the deserializer.
        Parameters:
        resolvers -
      • addTypeRestrict

        public void addTypeRestrict(java.lang.Class type,
                           java.lang.String fieldName,
                           JsonConverter.FieldInfo restrict)
        
        Adds a type definition that indicates a description of a field for a type The interface is mainly used to solve the deserialization of List, Set, Map and other types, the deserialization class does not know the type of collection elements.
      • isReadable

        public boolean isReadable(java.lang.Class<?> arg0,
                         java.lang.reflect.Type arg1,
                         java.lang.annotation.Annotation[] arg2,
                         javax.ws.rs.core.MediaType arg3)
        

        Determines whether the request body can be deserialized as a Java object.

        Specified by:
        isReadable in interface javax.ws.rs.ext.MessageBodyReader<java.lang.Object>
        Parameters:
        arg0 - A class of descrambled Java objects.
        arg1 - The type of the Java object that is deserialized.
        arg2 - Mark.
        arg3 - media type.
        Returns:
        can be serialized.
      • readFrom

        public java.lang.Object readFrom(java.lang.Class<java.lang.Object> type,
                                java.lang.reflect.Type genericType,
                                java.lang.annotation.Annotation[] annotations,
                                javax.ws.rs.core.MediaType mediaType,
                                javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> httpHeaders,
                                java.io.InputStream entityStream)
                                  throws java.io.IOException,
                                         javax.ws.rs.WebApplicationException
        

        The request body is deserialized into Java objects.

        Specified by:
        readFrom in interface javax.ws.rs.ext.MessageBodyReader<java.lang.Object>
        Parameters:
        type - A class of descrambled Java objects.
        genericType - The type of the Java object that is deserialized.
        annotations - annotation.
        mediaType - media type.
        httpHeaders - Request body form.
        entityStream - Request body stream.
        Returns:
        Java Object.
        Throws:
        java.io.IOException - IO abnormal.
        javax.ws.rs.WebApplicationException - Web Application exception.