java.lang.Object
org.glassfish.jersey.jackson.internal.jackson.jaxrs.base.ProviderBase<JacksonJsonProvider,com.fasterxml.jackson.databind.ObjectMapper,JsonEndpointConfig,JsonMapperConfigurator>
org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider
All Implemented Interfaces:
com.fasterxml.jackson.core.Versioned, MessageBodyReader<Object>, MessageBodyWriter<Object>
Direct Known Subclasses:
JacksonJaxbJsonProvider

@Provider @Consumes("*/*") @Produces({"application/json","text/json","*/*"}) public class JacksonJsonProvider extends ProviderBase<JacksonJsonProvider,com.fasterxml.jackson.databind.ObjectMapper,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 Provider that returns ObjectMappers.
  • By doing none of above, in which case a default mapper instance is constructed (and configured if configuration methods are called)
The last method ("do nothing specific") is often good enough; explicit passing of Mapper is simple and explicit; and Provider-based method may make sense with Depedency Injection frameworks, or if Mapper has to be configured differently for different media types.

Note that the default mapper instance will be automatically created if one of explicit configuration methods (like ProviderBase.configure(org.glassfish.jersey.jackson.internal.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 Details

    • MIME_JAVASCRIPT

      public static final String MIME_JAVASCRIPT
      See Also:
    • MIME_JAVASCRIPT_MS

      public static final String MIME_JAVASCRIPT_MS
      See Also:
    • BASIC_ANNOTATIONS

      public static final Annotations[] 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

      protected String _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 Providers _providers
      Injectable context object used to locate configured instance of ObjectMapper to 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(Annotations... annotationsToUse)
      Parameters:
      annotationsToUse - Annotation set(s) to use for configuring data binding
    • JacksonJsonProvider

      public JacksonJsonProvider(com.fasterxml.jackson.databind.ObjectMapper mapper)
    • JacksonJsonProvider

      public JacksonJsonProvider(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
    • JacksonJsonProvider

      protected JacksonJsonProvider(JsonMapperConfigurator configurator)
  • Method Details