Top Fields Constructors Methods
tools.jackson.jaxrs.base

public abstract Class ProviderBase<THIS extends ProviderBase<THIS, MAPPER, EP_CONFIG, MAPPER_CONFIG>, MAPPER extends ObjectMapper, EP_CONFIG extends EndpointConfigBase<EP_CONFIG>, MAPPER_CONFIG extends MapperConfiguratorBase<MAPPER_CONFIG, MAPPER>>

extends Object
implements MessageBodyReader<Object>, MessageBodyWriter<Object>, Versioned
Class Inheritance
All Implemented Interfaces
tools.jackson.core.Versioned, javax.ws.rs.ext.MessageBodyWriter, javax.ws.rs.ext.MessageBodyReader
Imports
java.io.*, java.lang.annotation.Annotation, java.lang.reflect.Type, java.util.*, java.util.concurrent.atomic.AtomicReference, javax.ws.rs.core.*, javax.ws.rs.ext.MessageBodyReader, .MessageBodyWriter, tools.jackson.core.*, tools.jackson.databind.*, tools.jackson.databind.type.TypeFactory, tools.jackson.databind.util.LookupCache, .SimpleLookupCache, tools.jackson.jaxrs.base.ProviderBase, tools.jackson.jaxrs.cfg.*, tools.jackson.jaxrs.util.ClassKey

Field Summary

Modifier and TypeField and Description
protected HashMap<ClassKey, Boolean>
_cfgCustomUntouchables

Map that contains overrides to default list of untouchable types: true meaning that entry is untouchable, false that is is not.

protected Class<?>
_defaultReadView

View to use for reading if none defined for the end point.

protected Class<?>
_defaultWriteView

View to use for writing if none defined for the end point.

protected int
_jaxRSFeatures

Feature flags set.

protected final MAPPER_CONFIG
_mapperConfig

Helper object used for encapsulating configuration aspects of ObjectMapper

protected final AtomicReference<IOException>
protected final LookupCache<AnnotationBundleKey, EP_CONFIG>
_readers

Cache for resolved endpoint configurations when reading JSON data

public static final Class<?>[]
public static final HashSet<ClassKey>
public static final Class<?>[]
protected final LookupCache<AnnotationBundleKey, EP_CONFIG>
_writers

Cache for resolved endpoint configurations when writing JSON data

protected static final String
public static final Class<?>[]
DEFAULT_UNREADABLES

These are classes that we never use for reading (never try to deserialize instances of these types).

protected static final HashSet<ClassKey>
DEFAULT_UNTOUCHABLES

Looks like we need to worry about accidental data binding for types we shouldn't be handling.

public static final Class<?>[]
DEFAULT_UNWRITABLES

These are classes that we never use for writing (never try to serialize instances of these types).

public static final String
HEADER_CONTENT_TYPE_OPTIONS

This header is useful on Windows, trying to deal with potential XSS attacks.

protected static final int

Constructor Summary

AccessConstructor and Description
protected
ProviderBase(MAPPER_CONFIG mconfig)

protected
ProviderBase()
Deprecated

Constructor that is only added to resolve issue #10; problems with combination of RESTeasy and CDI.

protected
ProviderBase(MAPPER_CONFIG mconfig, LookupCache<AnnotationBundleKey, EP_CONFIG> readerCache, LookupCache<AnnotationBundleKey, EP_CONFIG> writerCache)

Method Summary

Modifier and TypeMethod and Description
protected static void
_addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself)

protected EP_CONFIG
_configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView)

protected abstract EP_CONFIG
_configForReading(ObjectReader reader, Annotation[] annotations)

protected EP_CONFIG
_configForWriting(MAPPER mapper, Annotation[] annotations, Class<?> defaultView)

protected abstract EP_CONFIG
_configForWriting(ObjectWriter writer, Annotation[] annotations)

protected static boolean
_containedIn(Class<?> mainType, HashSet<ClassKey> set)

protected JsonGenerator
_createGenerator(ObjectWriter writer, OutputStream rawStream, JsonEncoding enc)

Overridable helper method called to create a JsonGenerator for writing contents into given raw OutputStream.

protected NoContentException
protected JsonParser
_createParser(ObjectReader reader, InputStream rawStream)

Overridable helper method called to create a JsonParser for reading contents of given raw InputStream.

protected EP_CONFIG
_endpointForReading(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders)

Overridable helper method that will basically fetch representation of the endpoint that can be used to get ObjectReader to use for deserializing content.

protected EP_CONFIG
_endpointForWriting(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders)

protected Boolean
protected boolean
_isIgnorableForReading(ClassKey typeKey)

Overridable helper method called to check whether given type is a known "ignorable type" (in context of reading), values of which are not bound from content.

protected boolean
_isIgnorableForWriting(ClassKey typeKey)

Overridable helper method called to check whether given type is a known "ignorable type" (in context of reading), values of which can not be written out.

protected boolean
_isSpecialReadable(Class<?> type)

Overridable helper method used to allow handling of somewhat special types for reading

protected abstract MAPPER
_locateMapperViaProvider(Class<?> type, MediaType mediaType)

Helper method that is called if no mapper has been explicitly configured.

protected void
_modifyHeaders(Object value, Class<?> type, Type genericType, Annotation[] annotations, MultivaluedMap<String, Object> httpHeaders, EP_CONFIG endpoint)

Overridable method used for adding optional response headers before serializing response object.

private final THIS
public void
addUntouchable(Class<?>
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
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).

public THIS
configure(JaxRSFeature feature, boolean state)

public THIS
public THIS
configure(SerializationFeature f, boolean state)

public THIS
public THIS
public THIS
public THIS
public THIS
public THIS
public THIS
public THIS
protected JsonEncoding
findEncoding(MediaType mediaType, MultivaluedMap<String, Object> httpHeaders)

Helper method to use for determining desired output encoding.

protected static List<Class<?>>
findSuperTypes(Class<?> cls, Class<?> endBefore)

protected static List<Class<?>>
findSuperTypes(Class<?> cls, Class<?> endBefore, List<Class<?>> result)

public long
getSize(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Overrides default javax.ws.rs.ext.MessageBodyWriter.getSize.

Method that JAX-RS container calls to try to figure out serialized length of given value.

protected abstract boolean
hasMatchingMediaType(MediaType mediaType)

Helper method used to check whether given media type is supported by this provider.

protected boolean
hasMatchingMediaTypeForReading(MediaType mediaType)

Helper method used to check whether given media type is supported by this provider for read operations (when binding input data such as POST body).

protected boolean
hasMatchingMediaTypeForWriting(MediaType mediaType)

Helper method used to check whether given media type is supported by this provider for writing operations, such as when converting response object to response body of request (like GET or POST).

public boolean
public boolean
isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Implements javax.ws.rs.ext.MessageBodyReader.isReadable.

Method that JAX-RS container calls to try to check whether values of given type (and media type) can be deserialized by this provider.

public boolean
isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Implements javax.ws.rs.ext.MessageBodyWriter.isWriteable.

Method that JAX-RS container calls to try to check whether given value (of specified type) can be serialized by this provider.

public MAPPER
locateMapper(Class<?>
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.
type
,
MediaType
Declared media type for the instance to process: not used by this method, but will be passed to ContextResolver as is.
mediaType
)

Method called to locate ObjectMapper to use for serialization and deserialization.

public Object
readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)

Implements javax.ws.rs.ext.MessageBodyReader.readFrom.

Method that JAX-RS container calls to deserialize given value.

public void
removeUntouchable(Class<?> type)

Method for removing definition of specified type as untouchable: usually only

public void
setAnnotationsToUse(AnnotationIntrospector
AnnotationIntrospector to configure mapper to use (null to leave it as default one)
aiOverride
)

Method for overriding AnnotationIntrospector to use instead of default JacksonAnnotationIntrospector: often used to add JAXB-backed introspector.

public THIS
setDefaultReadView(Class<?> view)

Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.

public THIS
setDefaultView(Class<?> view)

Method for specifying JSON View to use for reading and writing content when end point does not have explicit View annotations.

public THIS
setDefaultWriteView(Class<?> view)

Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.

public void
setMapper(MAPPER 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.

public void
writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)

Implements javax.ws.rs.ext.MessageBodyWriter.writeTo.

Method that JAX-RS container calls to serialize given value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_cfgCustomUntouchablesback to summary
protected HashMap<ClassKey, Boolean> _cfgCustomUntouchables

Map that contains overrides to default list of untouchable types: true meaning that entry is untouchable, false that is is not.

_defaultReadViewback to summary
protected Class<?> _defaultReadView

View to use for reading if none defined for the end point.

_defaultWriteViewback to summary
protected Class<?> _defaultWriteView

View to use for writing if none defined for the end point.

_jaxRSFeaturesback to summary
protected int _jaxRSFeatures

Feature flags set.

_mapperConfigback to summary
protected final MAPPER_CONFIG _mapperConfig

Helper object used for encapsulating configuration aspects of ObjectMapper

_noContentExceptionRefback to summary
protected final AtomicReference<IOException> _noContentExceptionRef
_readersback to summary
protected final LookupCache<AnnotationBundleKey, EP_CONFIG> _readers

Cache for resolved endpoint configurations when reading JSON data

_unreadableClassesback to summary
public static final Class<?>[] _unreadableClasses
_untouchablesback to summary
public static final HashSet<ClassKey> _untouchables
_unwritableClassesback to summary
public static final Class<?>[] _unwritableClasses
_writersback to summary
protected final LookupCache<AnnotationBundleKey, EP_CONFIG> _writers

Cache for resolved endpoint configurations when writing JSON data

CLASS_NAME_NO_CONTENT_EXCEPTIONback to summary
protected static final String CLASS_NAME_NO_CONTENT_EXCEPTION
DEFAULT_UNREADABLESback to summary
public static final Class<?>[] DEFAULT_UNREADABLES

These are classes that we never use for reading (never try to deserialize instances of these types).

DEFAULT_UNTOUCHABLESback to summary
protected static final HashSet<ClassKey> DEFAULT_UNTOUCHABLES

Looks like we need to worry about accidental data binding for types we shouldn't be handling. This is probably not a very good way to do it, but let's start by blacklisting things we are not to handle.

(why ClassKey? since plain old Class has no hashCode() defined, lookups are painfully slow)

DEFAULT_UNWRITABLESback to summary
public static final Class<?>[] DEFAULT_UNWRITABLES

These are classes that we never use for writing (never try to serialize instances of these types).

HEADER_CONTENT_TYPE_OPTIONSback to summary
public static final String HEADER_CONTENT_TYPE_OPTIONS

This header is useful on Windows, trying to deal with potential XSS attacks.

JAXRS_FEATURE_DEFAULTSback to summary
protected static final int JAXRS_FEATURE_DEFAULTS

Constructor Detail

ProviderBaseback to summary
protected ProviderBase(MAPPER_CONFIG mconfig)
ProviderBaseback to summary
protected ProviderBase()

Deprecated

Constructor that is only added to resolve issue #10; problems with combination of RESTeasy and CDI. Should NOT be used by any code explicitly; only exists for proxy support.

Annotations
@Deprecated
ProviderBaseback to summary
protected ProviderBase(MAPPER_CONFIG mconfig, LookupCache<AnnotationBundleKey, EP_CONFIG> readerCache, LookupCache<AnnotationBundleKey, EP_CONFIG> writerCache)

Method Detail

_addSuperTypesback to summary
protected static void _addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself)
_configForReadingback to summary
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView)
_configForReadingback to summary
protected abstract EP_CONFIG _configForReading(ObjectReader reader, Annotation[] annotations)
_configForWritingback to summary
protected EP_CONFIG _configForWriting(MAPPER mapper, Annotation[] annotations, Class<?> defaultView)
_configForWritingback to summary
protected abstract EP_CONFIG _configForWriting(ObjectWriter writer, Annotation[] annotations)
_containedInback to summary
protected static boolean _containedIn(Class<?> mainType, HashSet<ClassKey> set)
_createGeneratorback to summary
protected JsonGenerator _createGenerator(ObjectWriter writer, OutputStream rawStream, JsonEncoding enc) throws JacksonException

Overridable helper method called to create a JsonGenerator for writing contents into given raw OutputStream.

_createNoContentExceptionback to summary
protected NoContentException _createNoContentException()
_createParserback to summary
protected JsonParser _createParser(ObjectReader reader, InputStream rawStream) throws JacksonException

Overridable helper method called to create a JsonParser for reading contents of given raw InputStream. May return null to indicate that Stream is empty; that is, contains no content.

_endpointForReadingback to summary
protected EP_CONFIG _endpointForReading(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders)

Overridable helper method that will basically fetch representation of the endpoint that can be used to get ObjectReader to use for deserializing content.

_endpointForWritingback to summary
protected EP_CONFIG _endpointForWriting(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders)
_findCustomUntouchableback to summary
protected Boolean _findCustomUntouchable(Class<?> mainType)
_isIgnorableForReadingback to summary
protected boolean _isIgnorableForReading(ClassKey typeKey)

Overridable helper method called to check whether given type is a known "ignorable type" (in context of reading), values of which are not bound from content.

_isIgnorableForWritingback to summary
protected boolean _isIgnorableForWriting(ClassKey typeKey)

Overridable helper method called to check whether given type is a known "ignorable type" (in context of reading), values of which can not be written out.

_isSpecialReadableback to summary
protected boolean _isSpecialReadable(Class<?> type)

Overridable helper method used to allow handling of somewhat special types for reading

_locateMapperViaProviderback to summary
protected abstract MAPPER _locateMapperViaProvider(Class<?> type, MediaType mediaType)

Helper method that is called if no mapper has been explicitly configured.

_modifyHeadersback to summary
protected void _modifyHeaders(Object value, Class<?> type, Type genericType, Annotation[] annotations, MultivaluedMap<String, Object> httpHeaders, EP_CONFIG endpoint) throws JacksonException

Overridable method used for adding optional response headers before serializing response object.

_thisback to summary
private final THIS _this()
Annotations
@SuppressWarnings:unchecked
addUntouchableback to summary
public 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).

Parameters
type:Class<?>

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

configureback to summary
public THIS configure(JaxRSFeature feature, boolean state)
configureback to summary
public THIS configure(DeserializationFeature f, boolean state)
configureback to summary
public THIS configure(SerializationFeature f, boolean state)
disableback to summary
public THIS disable(JaxRSFeature feature)
disableback to summary
public THIS disable(JaxRSFeature first, JaxRSFeature... f2)
disableback to summary
public THIS disable(DeserializationFeature f)
disableback to summary
public THIS disable(SerializationFeature f)
enableback to summary
public THIS enable(JaxRSFeature feature)
enableback to summary
public THIS enable(JaxRSFeature first, JaxRSFeature... f2)
enableback to summary
public THIS enable(DeserializationFeature f)
enableback to summary
public THIS enable(SerializationFeature f)
findEncodingback to summary
protected JsonEncoding findEncoding(MediaType mediaType, MultivaluedMap<String, Object> httpHeaders)

Helper method to use for determining desired output encoding. For now, will always just use UTF-8...

findSuperTypesback to summary
protected static List<Class<?>> findSuperTypes(Class<?> cls, Class<?> endBefore)
findSuperTypesback to summary
protected static List<Class<?>> findSuperTypes(Class<?> cls, Class<?> endBefore, List<Class<?>> result)
getSizeback to summary
public long getSize(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Overrides default javax.ws.rs.ext.MessageBodyWriter.getSize.

Method that JAX-RS container calls to try to figure out serialized length of given value. Since computation of this length is about as expensive as serialization itself, implementation will return -1 to denote "not known", so that container will determine length from actual serialized output (if needed).

Annotations
@Override
hasMatchingMediaTypeback to summary
protected abstract boolean hasMatchingMediaType(MediaType mediaType)

Helper method used to check whether given media type is supported by this provider.

hasMatchingMediaTypeForReadingback to summary
protected boolean hasMatchingMediaTypeForReading(MediaType mediaType)

Helper method used to check whether given media type is supported by this provider for read operations (when binding input data such as POST body).

Default implementation simply calls hasMatchingMediaType.

hasMatchingMediaTypeForWritingback to summary
protected boolean hasMatchingMediaTypeForWriting(MediaType mediaType)

Helper method used to check whether given media type is supported by this provider for writing operations, such as when converting response object to response body of request (like GET or POST).

Default implementation simply calls hasMatchingMediaType.

isEnabledback to summary
public boolean isEnabled(JaxRSFeature f)
isReadableback to summary
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Implements javax.ws.rs.ext.MessageBodyReader.isReadable.

Method that JAX-RS container calls to try to check whether values of given type (and media type) can be deserialized by this provider. Implementation will first check that expected media type is a JSON type (via call to hasMatchingMediaType); 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.

Note

in 2.x also checked (if configured) for "canDeserialize()", but with 3.x that is not done since there that detection never worked in a useful manner.

Annotations
@Override
isWriteableback to summary
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Implements javax.ws.rs.ext.MessageBodyWriter.isWriteable.

Method that JAX-RS container calls to try to check whether given value (of specified type) can be serialized by this provider. Implementation will first check that expected media type is expected one (by call to hasMatchingMediaType); then verify that type is not one of "untouchable" types (types we will never automatically handle).

Note

in 2.x also checked (if configured) for "canSerialize()", but with 3.x that is not done since there that detection never worked in a useful manner.

Annotations
@Override
locateMapperback to summary
public MAPPER locateMapper(Class<?> type, MediaType mediaType)

Method called to locate ObjectMapper to use for serialization and deserialization. Exact logic depends on setting of JaxRSFeature#DYNAMIC_OBJECT_MAPPER_LOOKUP.

If JaxRSFeature#DYNAMIC_OBJECT_MAPPER_LOOKUP is disabled (default setting unless changed), behavior is as follows:

  1. If an instance has been explicitly defined by setMapper (or non-null instance passed in constructor), that will be used.
  2. 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).
  3. Finally, if no mapper is found, will return a default unconfigured ObjectMapper instance (one constructed with default constructor and not modified in any way)

If JaxRSFeature#DYNAMIC_OBJECT_MAPPER_LOOKUP is enabled, steps 1 and 2 are reversed, such that JAX-RS ContextResolver is first used, and only if none is defined will configured mapper be used.

Parameters
type:Class<?>

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:MediaType

Declared media type for the instance to process: not used by this method, but will be passed to ContextResolver as is.

readFromback to summary
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws JacksonException, NoContentException

Implements javax.ws.rs.ext.MessageBodyReader.readFrom.

Method that JAX-RS container calls to deserialize given value.

Annotations
@Override
removeUntouchableback to summary
public void removeUntouchable(Class<?> type)

Method for removing definition of specified type as untouchable: usually only

setAnnotationsToUseback to summary
public void setAnnotationsToUse(AnnotationIntrospector aiOverride)

Method for overriding AnnotationIntrospector to use instead of default JacksonAnnotationIntrospector: often used to add JAXB-backed introspector.

Parameters
aiOverride:AnnotationIntrospector

AnnotationIntrospector to configure mapper to use (null to leave it as default one)

setDefaultReadViewback to summary
public THIS setDefaultReadView(Class<?> view)

Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.

setDefaultViewback to summary
public THIS setDefaultView(Class<?> view)

Method for specifying JSON View to use for reading and writing content when end point does not have explicit View annotations. Functionally equivalent to: setDefaultReadView(view); setDefaultWriteView(view);

setDefaultWriteViewback to summary
public THIS setDefaultWriteView(Class<?> view)

Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.

setMapperback to summary
public void setMapper(MAPPER 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. Default setting is null.

writeToback to summary
public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws JacksonException

Implements javax.ws.rs.ext.MessageBodyWriter.writeTo.

Method that JAX-RS container calls to serialize given value.

Annotations
@Override