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:
-
MessageBodyReaderMessageBodyWriter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CharsetDeprecated.protected StringDeprecated.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.ProvidersInjectable context object used to locate configured instance ofFastJsonConfigto use for actual serialization. -
Constructor Summary
ConstructorsConstructorDescriptionCan 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.longgetSize(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 booleanhasMatchingMediaType(javax.ws.rs.core.MediaType mediaType) Check media type like "application/json".protected booleanisAssignableFrom(Class<?> type, Class<?>[] classes) Check some are interface/abstract classes to exclude.booleanisReadable(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 booleanisValidType(Class<?> type, Annotation[] classAnnotations) Check whether a class can be serialized or deserialized.booleanisWriteable(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 FastJsonConfiglocateConfigProvider(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.voidsetCharset(Charset charset) Deprecated.voidsetDateFormat(String dateFormat) Deprecated.voidsetFastJsonConfig(FastJsonConfig fastJsonConfig) voidsetFeatures(SerializerFeature... features) Deprecated.voidsetFilters(SerializeFilter... filters) Deprecated.setPretty(boolean p) Set pretty formatvoidwriteTo(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 ofFastJsonConfigto 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:
isWriteablein 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:
getSizein 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:
writeToin interfacejavax.ws.rs.ext.MessageBodyWriter<Object>- Throws:
IOExceptionjavax.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:
isReadablein 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:
readFromin interfacejavax.ws.rs.ext.MessageBodyReader<Object>- Throws:
IOExceptionjavax.ws.rs.WebApplicationException
-
locateConfigProvider
Helper method that is called if no config has been explicitly configured.
-