java.lang.Object
tools.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,tools.jackson.databind.json.JsonMapper,JsonEndpointConfig,JsonMapperConfigurator>
tools.jackson.jaxrs.json.JacksonJsonProvider
- All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<Object>,javax.ws.rs.ext.MessageBodyWriter<Object>,tools.jackson.core.Versioned
- Direct Known Subclasses:
JacksonJaxbJsonProvider
@Provider
@Consumes("*/*")
@Produces({"application/json","text/json","*/*"})
public class JacksonJsonProvider
extends tools.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,tools.jackson.databind.json.JsonMapper,JsonEndpointConfig,JsonMapperConfigurator>
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:
- By explicitly passing mapper to use in constructor
- By explictly setting mapper to use by
ProviderBase.setMapper(MAPPER) - By defining JAX-RS
Providerthat returnsObjectMappers. - 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(tools.jackson.jaxrs.cfg.JaxRSFeature, 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 (JacksonJaxbJsonProvider) 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)
- Author:
- Tatu Saloranta
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringJSONP function name to use for automatic JSONP wrapping, if any; if null, no JSONP wrapping is done.protected javax.ws.rs.ext.ProvidersInjectable context object used to locate configured instance ofJsonMapperto use for actual serialization.static final Stringstatic final StringFields inherited from class tools.jackson.jaxrs.base.ProviderBase
_cfgCustomUntouchables, _defaultReadView, _defaultWriteView, _jaxRSFeatures, _mapperConfig, _noContentExceptionRef, _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.JacksonJsonProvider(tools.jackson.databind.json.JsonMapper mapper) JacksonJsonProvider(tools.jackson.databind.json.JsonMapper mapper, tools.jackson.databind.AnnotationIntrospector aiOverride) Constructor to use when a custom mapper (usually components like serializer/deserializer factories that have been configured) is to be used. -
Method Summary
Modifier and TypeMethodDescriptionprotected JsonEndpointConfig_configForReading(tools.jackson.databind.ObjectReader reader, Annotation[] annotations) protected JsonEndpointConfig_configForWriting(tools.jackson.databind.ObjectWriter writer, Annotation[] annotations) protected tools.jackson.databind.json.JsonMapper_locateMapperViaProvider(Class<?> type, javax.ws.rs.core.MediaType mediaType) protected booleanhasMatchingMediaType(javax.ws.rs.core.MediaType mediaType) Helper method used to check whether given media type is supported by this provider.voidsetJSONPFunctionName(String fname) tools.jackson.core.Versionversion()Method that will return version information stored in and read from jar that contains this class.Methods inherited from class tools.jackson.jaxrs.base.ProviderBase
_addSuperTypes, _configForReading, _configForWriting, _containedIn, _createGenerator, _createNoContentException, _createParser, _endpointForReading, _endpointForWriting, _findCustomUntouchable, _isIgnorableForReading, _isIgnorableForWriting, _isSpecialReadable, _modifyHeaders, addUntouchable, configure, configure, configure, disable, disable, disable, disable, enable, enable, enable, enable, findEncoding, findSuperTypes, findSuperTypes, getSize, hasMatchingMediaTypeForReading, hasMatchingMediaTypeForWriting, isEnabled, isReadable, isWriteable, locateMapper, readFrom, removeUntouchable, setAnnotationsToUse, setDefaultReadView, setDefaultView, setDefaultWriteView, setMapper, writeTo
-
Field Details
-
MIME_JAVASCRIPT
- See Also:
-
MIME_JAVASCRIPT_MS
- See Also:
-
_jsonpFunctionName
JSONP function name to use for automatic JSONP wrapping, if any; if null, no JSONP wrapping is done. Note that this is the default value that can be overridden on per-endpoint basis. -
_providers
@Context protected javax.ws.rs.ext.Providers _providersInjectable context object used to locate configured instance ofJsonMapperto use for actual serialization.
-
-
Constructor Details
-
JacksonJsonProvider
public JacksonJsonProvider()Default constructor, usually used when provider is automatically configured to be used with JAX-RS implementation. -
JacksonJsonProvider
public JacksonJsonProvider(tools.jackson.databind.json.JsonMapper mapper) -
JacksonJsonProvider
public JacksonJsonProvider(tools.jackson.databind.json.JsonMapper mapper, tools.jackson.databind.AnnotationIntrospector aiOverride) Constructor to use when a custom mapper (usually components like serializer/deserializer factories that have been configured) is to be used.- Parameters:
aiOverride- AnnotationIntrospector to override default with, if any
-
-
Method Details
-
version
public tools.jackson.core.Version version()Method that will return version information stored in and read from jar that contains this class. -
setJSONPFunctionName
-
hasMatchingMediaType
protected boolean hasMatchingMediaType(javax.ws.rs.core.MediaType mediaType) Helper method used to check whether given media type is supported by this provider. Current implementation essentially checks to see whetherMediaType.getSubtype()returns "json" or something ending with "+json". Or "text/x-json" (since 2.3)- Specified by:
hasMatchingMediaTypein classtools.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,tools.jackson.databind.json.JsonMapper, JsonEndpointConfig, JsonMapperConfigurator>
-
_locateMapperViaProvider
protected tools.jackson.databind.json.JsonMapper _locateMapperViaProvider(Class<?> type, javax.ws.rs.core.MediaType mediaType) - Specified by:
_locateMapperViaProviderin classtools.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,tools.jackson.databind.json.JsonMapper, JsonEndpointConfig, JsonMapperConfigurator>
-
_configForReading
protected JsonEndpointConfig _configForReading(tools.jackson.databind.ObjectReader reader, Annotation[] annotations) - Specified by:
_configForReadingin classtools.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,tools.jackson.databind.json.JsonMapper, JsonEndpointConfig, JsonMapperConfigurator>
-
_configForWriting
protected JsonEndpointConfig _configForWriting(tools.jackson.databind.ObjectWriter writer, Annotation[] annotations) - Specified by:
_configForWritingin classtools.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,tools.jackson.databind.json.JsonMapper, JsonEndpointConfig, JsonMapperConfigurator>
-