Package com.fasterxml.jackson.jaxrs.cbor
Class JacksonCBORProvider
java.lang.Object
com.fasterxml.jackson.jaxrs.base.ProviderBase<JacksonCBORProvider,com.fasterxml.jackson.databind.ObjectMapper,CBOREndpointConfig,CBORMapperConfigurator>
com.fasterxml.jackson.jaxrs.cbor.JacksonCBORProvider
- All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned
,javax.ws.rs.ext.MessageBodyReader<Object>
,javax.ws.rs.ext.MessageBodyWriter<Object>
- Direct Known Subclasses:
JacksonJaxbCBORProvider
@Provider
@Consumes("*/*")
@Produces("*/*")
public class JacksonCBORProvider
extends ProviderBase<JacksonCBORProvider,com.fasterxml.jackson.databind.ObjectMapper,CBOREndpointConfig,CBORMapperConfigurator>
Basic implementation of JAX-RS abstractions (
MessageBodyReader
,
MessageBodyWriter
) needed for binding
CBOR ("application/cbor") 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:
- By explicitly passing mapper to use in constructor
- By explictly setting mapper to use by
ProviderBase.setMapper(MAPPER)
- By defining JAX-RS
Provider
that returnsObjectMapper
s. - By doing none of above, in which case a default mapper instance is constructed (and configured if configuration methods are called)
Note that the default mapper instance will be automatically created if
one of explicit configuration methods (like ProviderBase.configure(com.fasterxml.jackson.jaxrs.cfg.JaxRSFeature, boolean)
)
is called: if so, Provider-based introspection is NOT used, but the
resulting Mapper is used as configured.
Note that there is also a sub-class -- (JacksonJaxbCBORProvider
) -- that
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
FieldsModifier and TypeFieldDescriptionprotected javax.ws.rs.ext.Providers
Injectable context object used to locate configured instance ofObjectMapper
to use for actual serialization.static final Annotations[]
Default annotation sets to use, if not explicitly defined during construction: only Jackson annotations are used for the base class.Fields inherited from class com.fasterxml.jackson.jaxrs.base.ProviderBase
_cfgCheckCanDeserialize, _cfgCheckCanSerialize, _cfgCustomUntouchables, _defaultReadView, _defaultWriteView, _jaxRSFeatures, _mapperConfig, _readers, _unreadableClasses, _untouchables, _unwritableClasses, _writers, CLASS_NAME_NO_CONTENT_EXCEPTION, DEFAULT_UNREADABLES, DEFAULT_UNTOUCHABLES, DEFAULT_UNWRITABLES, HEADER_CONTENT_TYPE_OPTIONS, JAXRS_FEATURE_DEFAULTS
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, usually used when provider is automatically configured to be used with JAX-RS implementation.JacksonCBORProvider
(com.fasterxml.jackson.databind.ObjectMapper mapper) JacksonCBORProvider
(com.fasterxml.jackson.databind.ObjectMapper mapper, Annotations[] annotationsToUse) Constructor to use when a custom mapper (usually components like serializer/deserializer factories that have been configured) is to be used.JacksonCBORProvider
(Annotations... annotationsToUse) -
Method Summary
Modifier and TypeMethodDescriptionprotected CBOREndpointConfig
_configForReading
(com.fasterxml.jackson.databind.ObjectReader reader, Annotation[] annotations) protected CBOREndpointConfig
_configForWriting
(com.fasterxml.jackson.databind.ObjectWriter writer, Annotation[] annotations) protected com.fasterxml.jackson.databind.ObjectMapper
_locateMapperViaProvider
(Class<?> type, javax.ws.rs.core.MediaType mediaType) Method called to locateObjectMapper
to use for serialization and deserialization.protected boolean
hasMatchingMediaType
(javax.ws.rs.core.MediaType mediaType) Helper method used to check whether given media type is CBOR type or sub type.com.fasterxml.jackson.core.Version
version()
Method that will return version information stored in and read from jar that contains this class.Methods inherited from class com.fasterxml.jackson.jaxrs.base.ProviderBase
_addSuperTypes, _configForReading, _configForWriting, _containedIn, _createGenerator, _createNoContentException, _createParser, _endpointForReading, _endpointForWriting, _findCustomUntouchable, _isIgnorableForReading, _isIgnorableForWriting, _isSpecialReadable, _modifyHeaders, addUntouchable, checkCanDeserialize, checkCanSerialize, configure, configure, configure, configure, configure, disable, disable, disable, disable, disable, disable, enable, enable, enable, enable, enable, enable, findEncoding, findSuperTypes, findSuperTypes, getSize, hasMatchingMediaTypeForReading, hasMatchingMediaTypeForWriting, isEnabled, isReadable, isWriteable, locateMapper, readFrom, removeUntouchable, setAnnotationsToUse, setDefaultReadView, setDefaultView, setDefaultWriteView, setMapper, writeTo
-
Field Details
-
BASIC_ANNOTATIONS
Default annotation sets to use, if not explicitly defined during construction: only Jackson annotations are used for the base class. Sub-classes can use other settings. -
_providers
@Context protected javax.ws.rs.ext.Providers _providersInjectable context object used to locate configured instance ofObjectMapper
to use for actual serialization.
-
-
Constructor Details
-
JacksonCBORProvider
public JacksonCBORProvider()Default constructor, usually used when provider is automatically configured to be used with JAX-RS implementation. -
JacksonCBORProvider
- Parameters:
annotationsToUse
- Annotation set(s) to use for configuring data binding
-
JacksonCBORProvider
public JacksonCBORProvider(com.fasterxml.jackson.databind.ObjectMapper mapper) -
JacksonCBORProvider
public JacksonCBORProvider(com.fasterxml.jackson.databind.ObjectMapper mapper, Annotations[] annotationsToUse) Constructor to use when a custom mapper (usually components like serializer/deserializer factories that have been configured) is to be used.- Parameters:
annotationsToUse
- Sets of annotations (Jackson, JAXB) that provider should support
-
-
Method Details
-
version
public com.fasterxml.jackson.core.Version version()Method that will return version information stored in and read from jar that contains this class. -
hasMatchingMediaType
protected boolean hasMatchingMediaType(javax.ws.rs.core.MediaType mediaType) Helper method used to check whether given media type is CBOR type or sub type. Current implementation essentially checks to see whetherMediaType.getSubtype()
returns "cbor" or something ending with "+cbor".- Specified by:
hasMatchingMediaType
in classProviderBase<JacksonCBORProvider,
com.fasterxml.jackson.databind.ObjectMapper, CBOREndpointConfig, CBORMapperConfigurator>
-
_locateMapperViaProvider
protected com.fasterxml.jackson.databind.ObjectMapper _locateMapperViaProvider(Class<?> type, javax.ws.rs.core.MediaType mediaType) Method called to locateObjectMapper
to use for serialization and deserialization. If an instance has been explicitly defined byProviderBase.setMapper(MAPPER)
(or non-null instance passed in constructor), that will be used. If not, will try to locate it using standard JAX-RSContextResolver
mechanism, if it has been properly configured to access it (by JAX-RS runtime). Finally, if no mapper is found, will return a default unconfiguredObjectMapper
instance (one constructed with default constructor and not modified in any way)- Specified by:
_locateMapperViaProvider
in classProviderBase<JacksonCBORProvider,
com.fasterxml.jackson.databind.ObjectMapper, CBOREndpointConfig, CBORMapperConfigurator> - Parameters:
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 toContextResolver
as is.mediaType
- Declared media type for the instance to process: not used by this method, but will be passed toContextResolver
as is.
-
_configForReading
protected CBOREndpointConfig _configForReading(com.fasterxml.jackson.databind.ObjectReader reader, Annotation[] annotations) - Specified by:
_configForReading
in classProviderBase<JacksonCBORProvider,
com.fasterxml.jackson.databind.ObjectMapper, CBOREndpointConfig, CBORMapperConfigurator>
-
_configForWriting
protected CBOREndpointConfig _configForWriting(com.fasterxml.jackson.databind.ObjectWriter writer, Annotation[] annotations) - Specified by:
_configForWriting
in classProviderBase<JacksonCBORProvider,
com.fasterxml.jackson.databind.ObjectMapper, CBOREndpointConfig, CBORMapperConfigurator>
-