@Provider @Consumes(value="*/*") @Produces(value="*/*") public class JacksonJsonProvider extends ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
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:
ProviderBase.setMapper(MAPPER)
Provider
that returns ObjectMapper
s.
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: 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)
Modifier and Type | Field and Description |
---|---|
protected String |
_jsonpFunctionName
JSONP function name to use for automatic JSONP wrapping, if any;
if null, no JSONP wrapping is done.
|
protected Providers |
_providers
Injectable context object used to locate configured
instance of
ObjectMapper to use for actual
serialization. |
static Annotations[] |
BASIC_ANNOTATIONS
Default annotation sets to use, if not explicitly defined during
construction: only Jackson annotations are used for the base
class.
|
static String |
MIME_JAVASCRIPT |
static String |
MIME_JAVASCRIPT_MS |
_cfgCheckCanDeserialize, _cfgCheckCanSerialize, _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, noContentExceptionSupplier
Constructor and Description |
---|
JacksonJsonProvider()
Default constructor, usually used when provider is automatically
configured to be used with JAX-RS implementation.
|
JacksonJsonProvider(Annotations... annotationsToUse) |
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.
|
Modifier and Type | Method and Description |
---|---|
protected 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 boolean |
hasMatchingMediaType(MediaType mediaType)
Helper method used to check whether given media type
is supported by this provider.
|
protected boolean |
isJsonType(MediaType mediaType)
Deprecated.
Since 2.2 use
hasMatchingMediaType(MediaType) instead |
void |
setJSONPFunctionName(String fname) |
Version |
version()
Method that will return version information stored in and read from jar
that contains this class.
|
_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
public static final String MIME_JAVASCRIPT
public static final String MIME_JAVASCRIPT_MS
public static final Annotations[] BASIC_ANNOTATIONS
protected String _jsonpFunctionName
@Context protected Providers _providers
ObjectMapper
to use for actual
serialization.public JacksonJsonProvider()
public JacksonJsonProvider(Annotations... annotationsToUse)
annotationsToUse
- Annotation set(s) to use for configuring
data bindingpublic JacksonJsonProvider(ObjectMapper mapper)
public JacksonJsonProvider(ObjectMapper mapper, Annotations[] annotationsToUse)
annotationsToUse
- Sets of annotations (Jackson, JAXB) that provider should
supportpublic Version version()
public void setJSONPFunctionName(String fname)
protected boolean hasMatchingMediaType(MediaType mediaType)
MediaType.getSubtype()
returns "json" or something
ending with "+json".
Or "text/x-json" (since 2.3)hasMatchingMediaType
in class ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
protected ObjectMapper _locateMapperViaProvider(Class<?> type, MediaType mediaType)
ProviderBase
_locateMapperViaProvider
in class ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
protected JsonEndpointConfig _configForReading(ObjectReader reader, Annotation[] annotations)
_configForReading
in class ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
protected JsonEndpointConfig _configForWriting(ObjectWriter writer, Annotation[] annotations)
_configForWriting
in class ProviderBase<JacksonJsonProvider,ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
@Deprecated protected boolean isJsonType(MediaType mediaType)
hasMatchingMediaType(MediaType)
insteadCopyright © 2017 JBoss by Red Hat. All rights reserved.