Class 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 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 Dependency 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(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