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 Summary
Modifier and TypeFieldDescriptionprotected Charset
Deprecated.protected String
Deprecated.static final Class<?>[]
These are classes that we never use for reading (never try to deserialize instances of these types).static final Class<?>[]
These are classes that we never use for writing (never try to serialize instances of these types).protected SerializerFeature[]
Deprecated.protected SerializeFilter[]
Deprecated.protected javax.ws.rs.ext.Providers
Injectable context object used to locate configured instance ofFastJsonConfig
to use for actual serialization. -
Constructor Summary
ConstructorDescriptionCan serialize/deserialize all types.FastJsonProvider
(Class<?>[] clazzes) Only serialize/deserialize all types in clazzes.FastJsonProvider
(String charset) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Deprecated.Deprecated.Deprecated.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".protected boolean
hasMatchingMediaType
(javax.ws.rs.core.MediaType mediaType) Check media type like "application/json".protected boolean
isAssignableFrom
(Class<?> type, Class<?>[] classes) Check some are interface/abstract classes to exclude.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.protected boolean
isValidType
(Class<?> type, Annotation[] classAnnotations) Check whether a class can be serialized or deserialized.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.protected FastJsonConfig
locateConfigProvider
(Class<?> type, javax.ws.rs.core.MediaType mediaType) Helper method that is called if no config has been explicitly configured.readFrom
(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, String> httpHeaders, InputStream entityStream) Method that JAX-RS container calls to deserialize given value.void
setCharset
(Charset charset) Deprecated.void
setDateFormat
(String dateFormat) Deprecated.void
setFastJsonConfig
(FastJsonConfig fastJsonConfig) void
setFeatures
(SerializerFeature... features) Deprecated.void
setFilters
(SerializeFilter... filters) Deprecated.setPretty
(boolean p) Set pretty formatvoid
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) Method that JAX-RS container calls to serialize given value.
-
Field Details
-
DEFAULT_UNREADABLES
These are classes that we never use for reading (never try to deserialize instances of these types). -
DEFAULT_UNWRITABLES
These are classes that we never use for writing (never try to serialize instances of these types). -
charset
Deprecated. -
features
Deprecated. -
filters
Deprecated. -
dateFormat
Deprecated. -
providers
@Context protected javax.ws.rs.ext.Providers providersInjectable context object used to locate configured instance ofFastJsonConfig
to use for actual serialization.
-
-
Constructor Details
-
FastJsonProvider
public FastJsonProvider()Can serialize/deserialize all types. -
FastJsonProvider
Only serialize/deserialize all types in clazzes. -
FastJsonProvider
Deprecated.Instantiates a new Fast json provider.- Parameters:
charset
- the charset- See Also:
-
-
Method Details
-
getFastJsonConfig
- Returns:
- the fastJsonConfig.
- Since:
- 1.2.11
-
setFastJsonConfig
- Parameters:
fastJsonConfig
- the fastJsonConfig to set.- Since:
- 1.2.11
-
setPretty
Set pretty format -
getCharset
Deprecated.Gets charset.- Returns:
- the charset
- See Also:
-
setCharset
Deprecated.Sets charset.- Parameters:
charset
- the charset- See Also:
-
getDateFormat
Deprecated.Gets date format.- Returns:
- the date format
- See Also:
-
setDateFormat
Deprecated.Sets date format.- Parameters:
dateFormat
- the date format- See Also:
-
getFeatures
Deprecated.Get features serializer feature [].- Returns:
- the serializer feature []
- See Also:
-
setFeatures
Deprecated.Sets features.- Parameters:
features
- the features- See Also:
-
getFilters
Deprecated.Get filters serialize filter [].- Returns:
- the serialize filter []
- See Also:
-
setFilters
Deprecated.Sets filters.- Parameters:
filters
- the filters- See Also:
-
isAssignableFrom
Check some are interface/abstract classes to exclude.- Parameters:
type
- the typeclasses
- the classes- Returns:
- the boolean
-
isValidType
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 interfacejavax.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 interfacejavax.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.WebApplicationExceptionMethod that JAX-RS container calls to serialize given value.- Specified by:
writeTo
in interfacejavax.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 interfacejavax.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.WebApplicationExceptionMethod that JAX-RS container calls to deserialize given value.- Specified by:
readFrom
in interfacejavax.ws.rs.ext.MessageBodyReader<Object>
- Throws:
IOException
javax.ws.rs.WebApplicationException
-
locateConfigProvider
Helper method that is called if no config has been explicitly configured.
-