Class JacksonJsonProvider
java.lang.Object
com.fasterxml.jackson.jakarta.rs.base.ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider
- All Implemented Interfaces:
Versioned,MessageBodyReader<Object>,MessageBodyWriter<Object>
- Direct Known Subclasses:
JacksonXmlBindJsonProvider,ResteasyJackson2Provider
@Provider
@Consumes("*/*")
@Produces({"application/json","text/json","*/*"})
public class JacksonJsonProvider
extends ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
Basic implementation of Jakarta-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 Jakarta-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(com.fasterxml.jackson.jakarta.rs.cfg.JakartaRSFeature, boolean))
is called: if so, Provider-based introspection is NOT used, but the
resulting Mapper is used as configured.
There is also (JacksonXmlBindJsonProvider) which
is configured by default to use both Jackson and Jakarta XmlBin 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 ProvidersInjectable context object used to locate configured instance ofObjectMapperto 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.static final Stringstatic final StringFields inherited from class com.fasterxml.jackson.jakarta.rs.base.ProviderBase
_cfgCheckCanDeserialize, _cfgCheckCanSerialize, _cfgCustomUntouchables, _defaultReadView, _defaultWriteView, _jakartaRSFeatures, _mapperConfig, _readers, _unreadableClasses, _untouchables, _unwritableClasses, _writers, DEFAULT_UNREADABLES, DEFAULT_UNTOUCHABLES, DEFAULT_UNWRITABLES, HEADER_CONTENT_TYPE_OPTIONS, JAKARTA_RS_FEATURE_DEFAULTS -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, usually used when provider is automatically configured to be used with Jakarta-RS implementation.JacksonJsonProvider(ObjectMapper mapper) JacksonJsonProvider(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.JacksonJsonProvider(Annotations... annotationsToUse) -
Method Summary
Modifier and TypeMethodDescriptionprotected JsonEndpointConfig_configForReading(ObjectReader reader, Annotation[] annotations) protected JsonEndpointConfig_configForWriting(ObjectWriter writer, Annotation[] annotations) protected ObjectMapper_locateMapperViaProvider(Class<?> type, MediaType mediaType) Helper method that is called if no mapper has been explicitly configured.protected booleanhasMatchingMediaType(MediaType mediaType) Helper method used to check whether given media type is supported by this provider.voidsetJSONPFunctionName(String fname) version()Method that will return version information stored in and read from jar that contains this class.Methods inherited from class com.fasterxml.jackson.jakarta.rs.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
-
MIME_JAVASCRIPT
- See Also:
-
MIME_JAVASCRIPT_MS
- See Also:
-
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. -
_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
Injectable context object used to locate configured instance ofObjectMapperto use for actual serialization.
-
-
Constructor Details
-
JacksonJsonProvider
public JacksonJsonProvider()Default constructor, usually used when provider is automatically configured to be used with Jakarta-RS implementation. -
JacksonJsonProvider
- Parameters:
annotationsToUse- Annotation set(s) to use for configuring data binding
-
JacksonJsonProvider
-
JacksonJsonProvider
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, XmlBind) that provider should support
-
-
Method Details
-
version
Method that will return version information stored in and read from jar that contains this class.- Returns:
- Version of the component
-
setJSONPFunctionName
-
hasMatchingMediaType
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 classProviderBase<JacksonJsonProvider,ObjectMapper, JsonEndpointConfig, JsonMapperConfigurator> - Since:
- 2.2
-
_locateMapperViaProvider
Description copied from class:ProviderBaseHelper method that is called if no mapper has been explicitly configured.- Specified by:
_locateMapperViaProviderin classProviderBase<JacksonJsonProvider,ObjectMapper, JsonEndpointConfig, JsonMapperConfigurator>
-
_configForReading
- Specified by:
_configForReadingin classProviderBase<JacksonJsonProvider,ObjectMapper, JsonEndpointConfig, JsonMapperConfigurator>
-
_configForWriting
- Specified by:
_configForWritingin classProviderBase<JacksonJsonProvider,ObjectMapper, JsonEndpointConfig, JsonMapperConfigurator>
-