|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.codehaus.jackson.jaxrs.JacksonJsonProvider
@Provider public class JacksonJsonProvider
Basic implementation of JAX-RS abstractions (MessageBodyReader,
MessageBodyWriter) needed for binding
JSON ("application/json") content to and from POJOs.
Currently most configurability is via caller configuring
ObjectMapper it uses to construct this provider.
Additionally it is possible to enable detection of which types
can be serialized/deserialized, which is not enabled by default
(since it is usually not needed).
| Field Summary | |
|---|---|
protected boolean |
_cfgCheckCanDeserialize
Whether we want to actually check that Jackson has a deserializer for given type. |
protected boolean |
_cfgCheckCanSerialize
Whether we want to actually check that Jackson has a serializer for given type. |
protected ObjectMapper |
_configuredMapper
Mapper provider was constructed with if any; if null, provider is dynamically located; and if that fails, default instance will be used. |
protected ObjectMapper |
_defaultMapper
|
protected Providers |
_providers
Injectable context object used to locate configured instance of ObjectMapper to use for actual
serialization. |
static Class<?>[] |
_unreadableClasses
|
static HashSet<ClassKey> |
_untouchables
06-Apr-2009, tatu: Looks like we need to worry about accidental data binding for types we shouldn't be handling. |
static Class<?>[] |
_unwritableClasses
|
| Constructor Summary | |
|---|---|
JacksonJsonProvider()
Default constructor, usually used when provider is automatically configured to be used with JAX-RS implementation. |
|
JacksonJsonProvider(ObjectMapper mapper)
Constructor to use when a custom mapper (usually components like serializer/deserializer factories that have been configured) is to be used. |
|
| Method Summary | |
|---|---|
protected JavaType |
_convertType(Type jdkType)
Method used to construct a JDK generic type into type definition Jackson understands. |
void |
checkCanDeserialize(boolean state)
|
void |
checkCanSerialize(boolean state)
|
long |
getSize(Object value,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
|
boolean |
isJsonType(MediaType mediaType)
|
boolean |
isReadable(Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
|
boolean |
isWriteable(Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
|
protected ObjectMapper |
locateMapper(Class<?> type,
MediaType mediaType)
Method called to locate ObjectMapper to use for serialization
and deserialization. |
Object |
readFrom(Class<Object> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String,String> httpHeaders,
InputStream entityStream)
|
void |
setMapper(ObjectMapper m)
Method that can be used to directly define ObjectMapper to use
for serialization and deserialization; if null, will use the standard
provider discovery from context instead. |
void |
writeTo(Object value,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String,Object> httpHeaders,
OutputStream entityStream)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final HashSet<ClassKey> _untouchables
public static final Class<?>[] _unreadableClasses
public static final Class<?>[] _unwritableClasses
protected ObjectMapper _defaultMapper
@Context protected Providers _providers
ObjectMapper to use for actual
serialization.
protected ObjectMapper _configuredMapper
protected boolean _cfgCheckCanSerialize
protected boolean _cfgCheckCanDeserialize
| Constructor Detail |
|---|
public JacksonJsonProvider()
public JacksonJsonProvider(ObjectMapper mapper)
| Method Detail |
|---|
public void checkCanDeserialize(boolean state)
public void checkCanSerialize(boolean state)
public void setMapper(ObjectMapper m)
ObjectMapper to use
for serialization and deserialization; if null, will use the standard
provider discovery from context instead. Default setting is null.
public boolean isReadable(Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
isReadable in interface MessageBodyReader<Object>
public Object readFrom(Class<Object> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String,String> httpHeaders,
InputStream entityStream)
throws IOException
readFrom in interface MessageBodyReader<Object>IOException
public long getSize(Object value,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
getSize in interface MessageBodyWriter<Object>
public boolean isWriteable(Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
isWriteable in interface MessageBodyWriter<Object>
public void writeTo(Object value,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String,Object> httpHeaders,
OutputStream entityStream)
throws IOException
writeTo in interface MessageBodyWriter<Object>IOException
protected ObjectMapper locateMapper(Class<?> type,
MediaType mediaType)
ObjectMapper to use for serialization
and deserialization. If an instance has been explicitly defined by
setMapper(org.codehaus.jackson.map.ObjectMapper) (or non-null instance passed in constructor), that
will be used.
If not, will try to locate it using standard JAX-RS
ContextResolver mechanism, if it has been properly configured
to access it (by JAX-RS runtime).
Finally, if no mapper is found, will return a default unconfigured
ObjectMapper instance (one constructed with default constructor
and not modified in any way)
type - Class of object being serialized or deserialized;
not checked at this point, since it is assumed that unprocessable
classes have been already weeded out,
but will be passed to ContextResolver as is.mediaType - Declared media type for the instance to process:
not used by this method,
but will be passed to ContextResolver as is.public boolean isJsonType(MediaType mediaType)
protected JavaType _convertType(Type jdkType)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||