|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.fasterxml.jackson.jaxrs.xml.JacksonXMLProvider
@Provider public class JacksonXMLProvider
Basic implementation of JAX-RS abstractions (MessageBodyReader,
MessageBodyWriter) needed for binding
JSON ("application/json") content to and from Java Objects ("POJO"s).
Actual data binding functionality is implemented by ObjectMapper:
mapper to use can be configured in multiple ways:
setMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)
Provider that returns XmlMappers.
Note that the default mapper instance will be automatically created if
one of explicit configuration methods (like configure(com.fasterxml.jackson.databind.DeserializationFeature, boolean))
is called: if so, Provider-based introspection is NOT used, but the
resulting Mapper is used as configured.
Note: version 1.3 added a sub-class (JacksonJaxbXMLProvider) which
is configured by default to use both Jackson and JAXB annotations for configuration
(base class when used as-is defaults to using just Jackson annotations)
| 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 HashSet<ClassKey> |
_cfgCustomUntouchables
Set of types (classes) that provider should ignore for data binding |
protected MapperConfigurator |
_mapperConfig
Helper object used for encapsulating configuration aspects of XmlMapper |
protected javax.ws.rs.ext.Providers |
_providers
Injectable context object used to locate configured instance of XmlMapper to use for actual
serialization. |
protected com.fasterxml.jackson.databind.util.LRUMap<AnnotationBundleKey,EndpointConfig> |
_readers
Cache for resolved endpoint configurations when reading XML |
static Class<?>[] |
_unreadableClasses
These are classes that we never use for reading (never try to deserialize instances of these types). |
static HashSet<ClassKey> |
_untouchables
Looks like we need to worry about accidental data binding for types we shouldn't be handling. |
static Class<?>[] |
_unwritableClasses
These are classes that we never use for writing (never try to serialize instances of these types). |
protected com.fasterxml.jackson.databind.util.LRUMap<AnnotationBundleKey,EndpointConfig> |
_writers
Cache for resolved endpoint configurations when writing XML |
static Annotations[] |
BASIC_ANNOTATIONS
Default annotation sets to use, if not explicitly defined during construction: only Jackson annotations are used for the base class. |
| Constructor Summary | |
|---|---|
JacksonXMLProvider()
Default constructor, usually used when provider is automatically configured to be used with JAX-RS implementation. |
|
JacksonXMLProvider(Annotations... annotationsToUse)
|
|
JacksonXMLProvider(com.fasterxml.jackson.dataformat.xml.XmlMapper mapper)
|
|
JacksonXMLProvider(com.fasterxml.jackson.dataformat.xml.XmlMapper mapper,
Annotations[] annotationsToUse)
Constructor to use when a custom mapper (usually components like serializer/deserializer factories that have been configured) is to be used. |
|
| Method Summary | |
|---|---|
protected static boolean |
_containedIn(Class<?> mainType,
HashSet<ClassKey> set)
|
void |
addUntouchable(Class<?> type)
Method for marking specified type as "untouchable", meaning that provider will not try to read or write values of this type (or its subtypes). |
void |
checkCanDeserialize(boolean state)
Method for defining whether actual detection for existence of a deserializer for type should be done when isReadable(java.lang.Class>, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)
is called. |
void |
checkCanSerialize(boolean state)
Method for defining whether actual detection for existence of a serializer for type should be done when isWriteable(java.lang.Class>, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)
is called. |
JacksonXMLProvider |
configure(com.fasterxml.jackson.databind.DeserializationFeature f,
boolean state)
|
JacksonXMLProvider |
configure(com.fasterxml.jackson.core.JsonGenerator.Feature f,
boolean state)
|
JacksonXMLProvider |
configure(com.fasterxml.jackson.core.JsonParser.Feature f,
boolean state)
|
JacksonXMLProvider |
configure(com.fasterxml.jackson.databind.SerializationFeature f,
boolean state)
|
JacksonXMLProvider |
disable(com.fasterxml.jackson.databind.DeserializationFeature f,
boolean state)
|
JacksonXMLProvider |
disable(com.fasterxml.jackson.core.JsonGenerator.Feature f,
boolean state)
|
JacksonXMLProvider |
disable(com.fasterxml.jackson.core.JsonParser.Feature f,
boolean state)
|
JacksonXMLProvider |
disable(com.fasterxml.jackson.databind.SerializationFeature f,
boolean state)
|
JacksonXMLProvider |
enable(com.fasterxml.jackson.databind.DeserializationFeature f,
boolean state)
|
JacksonXMLProvider |
enable(com.fasterxml.jackson.core.JsonGenerator.Feature f,
boolean state)
|
JacksonXMLProvider |
enable(com.fasterxml.jackson.core.JsonParser.Feature f,
boolean state)
|
JacksonXMLProvider |
enable(com.fasterxml.jackson.databind.SerializationFeature f,
boolean state)
|
protected com.fasterxml.jackson.core.JsonEncoding |
findEncoding(javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
Helper method to use for determining desired output encoding. |
long |
getSize(Object value,
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. |
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 |
isReadableType(Class<?> type)
Helper method called to see if given type is readable, that is, acceptable Java type to bind from XML |
protected boolean |
isWritableType(Class<?> type)
Helper method called to see if given type is writable, that is, acceptable Java type to write out as XML. |
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 boolean |
isXMLType(javax.ws.rs.core.MediaType mediaType)
Helper method used to check whether given media type is XML type or sub type. |
com.fasterxml.jackson.dataformat.xml.XmlMapper |
locateMapper(Class<?> type,
javax.ws.rs.core.MediaType mediaType)
Method called to locate XmlMapper to use for serialization
and deserialization. |
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)
Method that JAX-RS container calls to deserialize given value. |
void |
setAnnotationsToUse(Annotations[] annotationsToUse)
Method for configuring which annotation sets to use (including none). |
void |
setMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper m)
Method that can be used to directly define XmlMapper to use
for serialization and deserialization; if null, will use the standard
provider discovery from context instead. |
com.fasterxml.jackson.core.Version |
version()
Method that will return version information stored in and read from jar that contains this class. |
void |
writeTo(Object value,
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Annotations[] BASIC_ANNOTATIONS
public static final HashSet<ClassKey> _untouchables
(why ClassKey? since plain old Class has no hashCode() defined, lookups are painfully slow)
public static final Class<?>[] _unreadableClasses
public static final Class<?>[] _unwritableClasses
protected final com.fasterxml.jackson.databind.util.LRUMap<AnnotationBundleKey,EndpointConfig> _readers
protected final com.fasterxml.jackson.databind.util.LRUMap<AnnotationBundleKey,EndpointConfig> _writers
protected final MapperConfigurator _mapperConfig
XmlMapper
protected HashSet<ClassKey> _cfgCustomUntouchables
@Context protected javax.ws.rs.ext.Providers _providers
XmlMapper to use for actual
serialization.
protected boolean _cfgCheckCanSerialize
protected boolean _cfgCheckCanDeserialize
| Constructor Detail |
|---|
public JacksonXMLProvider()
public JacksonXMLProvider(Annotations... annotationsToUse)
annotationsToUse - Annotation set(s) to use for configuring
data bindingpublic JacksonXMLProvider(com.fasterxml.jackson.dataformat.xml.XmlMapper mapper)
public JacksonXMLProvider(com.fasterxml.jackson.dataformat.xml.XmlMapper mapper,
Annotations[] annotationsToUse)
annotationsToUse - Sets of annotations (Jackson, JAXB) that provider should
support| Method Detail |
|---|
public com.fasterxml.jackson.core.Version version()
version in interface com.fasterxml.jackson.core.Versionedpublic void checkCanDeserialize(boolean state)
isReadable(java.lang.Class>, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)
is called.
public void checkCanSerialize(boolean state)
isWriteable(java.lang.Class>, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType)
is called.
public void setAnnotationsToUse(Annotations[] annotationsToUse)
annotationsToUse - Ordered list of annotation sets to use; if null,
defaultpublic void setMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper m)
XmlMapper to use
for serialization and deserialization; if null, will use the standard
provider discovery from context instead. Default setting is null.
public JacksonXMLProvider configure(com.fasterxml.jackson.databind.DeserializationFeature f,
boolean state)
public JacksonXMLProvider configure(com.fasterxml.jackson.databind.SerializationFeature f,
boolean state)
public JacksonXMLProvider configure(com.fasterxml.jackson.core.JsonParser.Feature f,
boolean state)
public JacksonXMLProvider configure(com.fasterxml.jackson.core.JsonGenerator.Feature f,
boolean state)
public JacksonXMLProvider enable(com.fasterxml.jackson.databind.DeserializationFeature f,
boolean state)
public JacksonXMLProvider enable(com.fasterxml.jackson.databind.SerializationFeature f,
boolean state)
public JacksonXMLProvider enable(com.fasterxml.jackson.core.JsonParser.Feature f,
boolean state)
public JacksonXMLProvider enable(com.fasterxml.jackson.core.JsonGenerator.Feature f,
boolean state)
public JacksonXMLProvider disable(com.fasterxml.jackson.databind.DeserializationFeature f,
boolean state)
public JacksonXMLProvider disable(com.fasterxml.jackson.databind.SerializationFeature f,
boolean state)
public JacksonXMLProvider disable(com.fasterxml.jackson.core.JsonParser.Feature f,
boolean state)
public JacksonXMLProvider disable(com.fasterxml.jackson.core.JsonGenerator.Feature f,
boolean state)
public void addUntouchable(Class<?> type)
type - Type to consider untouchable; can be any kind of class,
including abstract class or interface. No instance of this type
(including subtypes, i.e. types assignable to this type) will
be read or written by provider
public boolean isReadable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
isXMLType(javax.ws.rs.core.MediaType); then verify
that type is not one of "untouchable" types (types we will never
automatically handle), and finally that there is a deserializer
for type (iff checkCanDeserialize(boolean) has been called with
true argument -- otherwise assumption is there will be a handler)
isReadable in interface javax.ws.rs.ext.MessageBodyReader<Object>
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
readFrom in interface javax.ws.rs.ext.MessageBodyReader<Object>IOException
public long getSize(Object value,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
getSize in interface javax.ws.rs.ext.MessageBodyWriter<Object>
public boolean isWriteable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
isXMLType(javax.ws.rs.core.MediaType); then verify
that type is not one of "untouchable" types (types we will never
automatically handle), and finally that there is a serializer
for type (iff checkCanSerialize(boolean) has been called with
true argument -- otherwise assumption is there will be a handler)
isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<Object>
public void writeTo(Object value,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders,
OutputStream entityStream)
throws IOException
writeTo in interface javax.ws.rs.ext.MessageBodyWriter<Object>IOException
protected com.fasterxml.jackson.core.JsonEncoding findEncoding(javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
protected boolean isXMLType(javax.ws.rs.core.MediaType mediaType)
MediaType.getSubtype() returns "xml" or something
ending with "+xml".
protected boolean isReadableType(Class<?> type)
protected boolean isWritableType(Class<?> type)
public com.fasterxml.jackson.dataformat.xml.XmlMapper locateMapper(Class<?> type,
javax.ws.rs.core.MediaType mediaType)
XmlMapper to use for serialization
and deserialization. If an instance has been explicitly defined by
setMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) (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.
protected static boolean _containedIn(Class<?> mainType,
HashSet<ClassKey> set)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||