Class FastJsonProvider

java.lang.Object
com.alibaba.fastjson.support.jaxrs.FastJsonProvider
All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<Object>, javax.ws.rs.ext.MessageBodyWriter<Object>

@Provider @Consumes("*/*") @Produces("*/*") public class FastJsonProvider extends Object implements javax.ws.rs.ext.MessageBodyReader<Object>, javax.ws.rs.ext.MessageBodyWriter<Object>
Fastjson for JAX-RS Provider.
Since:
1.2.9
Author:
smallnest, VictorZeng
See Also:
  • MessageBodyReader
  • MessageBodyWriter
  • Field Details

    • DEFAULT_UNREADABLES

      public static final Class<?>[] DEFAULT_UNREADABLES
      These are classes that we never use for reading (never try to deserialize instances of these types).
    • DEFAULT_UNWRITABLES

      public static final Class<?>[] DEFAULT_UNWRITABLES
      These are classes that we never use for writing (never try to serialize instances of these types).
    • charset

      @Deprecated protected Charset charset
      Deprecated.
    • features

      @Deprecated protected SerializerFeature[] features
      Deprecated.
    • filters

      @Deprecated protected SerializeFilter[] filters
      Deprecated.
    • dateFormat

      @Deprecated protected String dateFormat
      Deprecated.
    • providers

      @Context protected javax.ws.rs.ext.Providers providers
      Injectable context object used to locate configured instance of FastJsonConfig to use for actual serialization.
  • Constructor Details

    • FastJsonProvider

      public FastJsonProvider()
      Can serialize/deserialize all types.
    • FastJsonProvider

      public FastJsonProvider(Class<?>[] clazzes)
      Only serialize/deserialize all types in clazzes.
    • FastJsonProvider

      @Deprecated public FastJsonProvider(String charset)
      Deprecated.
      Instantiates a new Fast json provider.
      Parameters:
      charset - the charset
      See Also:
  • Method Details

    • getFastJsonConfig

      public FastJsonConfig getFastJsonConfig()
      Returns:
      the fastJsonConfig.
      Since:
      1.2.11
    • setFastJsonConfig

      public void setFastJsonConfig(FastJsonConfig fastJsonConfig)
      Parameters:
      fastJsonConfig - the fastJsonConfig to set.
      Since:
      1.2.11
    • setPretty

      public FastJsonProvider setPretty(boolean p)
      Set pretty format
    • getCharset

      @Deprecated public Charset getCharset()
      Deprecated.
      Gets charset.
      Returns:
      the charset
      See Also:
    • setCharset

      @Deprecated public void setCharset(Charset charset)
      Deprecated.
      Sets charset.
      Parameters:
      charset - the charset
      See Also:
    • getDateFormat

      @Deprecated public String getDateFormat()
      Deprecated.
      Gets date format.
      Returns:
      the date format
      See Also:
    • setDateFormat

      @Deprecated public void setDateFormat(String dateFormat)
      Deprecated.
      Sets date format.
      Parameters:
      dateFormat - the date format
      See Also:
    • getFeatures

      @Deprecated public SerializerFeature[] getFeatures()
      Deprecated.
      Get features serializer feature [].
      Returns:
      the serializer feature []
      See Also:
    • setFeatures

      @Deprecated public void setFeatures(SerializerFeature... features)
      Deprecated.
      Sets features.
      Parameters:
      features - the features
      See Also:
    • getFilters

      @Deprecated public SerializeFilter[] getFilters()
      Deprecated.
      Get filters serialize filter [].
      Returns:
      the serialize filter []
      See Also:
    • setFilters

      @Deprecated public void setFilters(SerializeFilter... filters)
      Deprecated.
      Sets filters.
      Parameters:
      filters - the filters
      See Also:
    • isAssignableFrom

      protected boolean isAssignableFrom(Class<?> type, Class<?>[] classes)
      Check some are interface/abstract classes to exclude.
      Parameters:
      type - the type
      classes - the classes
      Returns:
      the boolean
    • isValidType

      protected boolean isValidType(Class<?> type, Annotation[] classAnnotations)
      Check whether a class can be serialized or deserialized. It can check based on packages, annotations on entities or explicit classes.
      Parameters:
      type - class need to check
      Returns:
      true if valid
    • hasMatchingMediaType

      protected boolean hasMatchingMediaType(javax.ws.rs.core.MediaType mediaType)
      Check media type like "application/json".
      Parameters:
      mediaType - media type
      Returns:
      true if the media type is valid
    • isWriteable

      public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Method that JAX-RS container calls to try to check whether given value (of specified type) can be serialized by this provider.
      Specified by:
      isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<Object>
    • getSize

      public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Method that JAX-RS container calls to try to figure out serialized length of given value. always return -1 to denote "not known".
      Specified by:
      getSize in interface javax.ws.rs.ext.MessageBodyWriter<Object>
    • writeTo

      public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream) throws IOException, javax.ws.rs.WebApplicationException
      Method that JAX-RS container calls to serialize given value.
      Specified by:
      writeTo in interface javax.ws.rs.ext.MessageBodyWriter<Object>
      Throws:
      IOException
      javax.ws.rs.WebApplicationException
    • isReadable

      public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Method that JAX-RS container calls to try to check whether values of given type (and media type) can be deserialized by this provider.
      Specified by:
      isReadable in interface javax.ws.rs.ext.MessageBodyReader<Object>
    • readFrom

      public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders, InputStream entityStream) throws IOException, javax.ws.rs.WebApplicationException
      Method that JAX-RS container calls to deserialize given value.
      Specified by:
      readFrom in interface javax.ws.rs.ext.MessageBodyReader<Object>
      Throws:
      IOException
      javax.ws.rs.WebApplicationException
    • locateConfigProvider

      protected FastJsonConfig locateConfigProvider(Class<?> type, javax.ws.rs.core.MediaType mediaType)
      Helper method that is called if no config has been explicitly configured.