Class ProviderBase<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>,MAPPER extends tools.jackson.databind.ObjectMapper,EP_CONFIG extends EndpointConfigBase<EP_CONFIG>,MAPPER_CONFIG extends MapperConfiguratorBase<MAPPER_CONFIG,MAPPER>>

java.lang.Object
tools.jackson.jakarta.rs.base.ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>
All Implemented Interfaces:
jakarta.ws.rs.ext.MessageBodyReader<Object>, jakarta.ws.rs.ext.MessageBodyWriter<Object>, tools.jackson.core.Versioned

public abstract class ProviderBase<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>,MAPPER extends tools.jackson.databind.ObjectMapper,EP_CONFIG extends EndpointConfigBase<EP_CONFIG>,MAPPER_CONFIG extends MapperConfiguratorBase<MAPPER_CONFIG,MAPPER>> extends Object implements jakarta.ws.rs.ext.MessageBodyReader<Object>, jakarta.ws.rs.ext.MessageBodyWriter<Object>, tools.jackson.core.Versioned
  • Field Details

    • HEADER_CONTENT_TYPE_OPTIONS

      public static final String HEADER_CONTENT_TYPE_OPTIONS
      This header is useful on Windows, trying to deal with potential XSS attacks.
      See Also:
    • DEFAULT_UNTOUCHABLES

      protected static final HashSet<ClassKey> DEFAULT_UNTOUCHABLES
      Looks like we need to worry about accidental data binding for types we shouldn't be handling. This is probably not a very good way to do it, but let's start by blacklisting things we are not to handle.

      (why ClassKey? since plain old Class has no hashCode() defined, lookups are painfully slow)

    • DEFAULT_UNREADABLES

      public static final Class<?>[] DEFAULT_UNREADABLES
      These are classes that we never use for reading (never try to deserialize instances of these types).
    • DEFAULT_UNWRITABLES

      public static final Class<?>[] DEFAULT_UNWRITABLES
      These are classes that we never use for writing (never try to serialize instances of these types).
    • JAKARTA_RS_FEATURE_DEFAULTS

      protected static final int JAKARTA_RS_FEATURE_DEFAULTS
    • _mapperConfig

      protected final MAPPER_CONFIG extends MapperConfiguratorBase<MAPPER_CONFIG,MAPPER> _mapperConfig
      Helper object used for encapsulating configuration aspects of ObjectMapper
    • _cfgCustomUntouchables

      protected HashMap<ClassKey,Boolean> _cfgCustomUntouchables
      Map that contains overrides to default list of untouchable types: true meaning that entry is untouchable, false that is is not.
    • _jakartaRSFeatures

      protected int _jakartaRSFeatures
      Feature flags set.
    • _defaultReadView

      protected Class<?> _defaultReadView
      View to use for reading if none defined for the end point.
    • _defaultWriteView

      protected Class<?> _defaultWriteView
      View to use for writing if none defined for the end point.
    • _untouchables

      public static final HashSet<ClassKey> _untouchables
    • _unreadableClasses

      public static final Class<?>[] _unreadableClasses
    • _unwritableClasses

      public static final Class<?>[] _unwritableClasses
    • _readers

      protected final tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG extends EndpointConfigBase<EP_CONFIG>> _readers
      Cache for resolved endpoint configurations when reading JSON data
    • _writers

      protected final tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG extends EndpointConfigBase<EP_CONFIG>> _writers
      Cache for resolved endpoint configurations when writing JSON data
  • Constructor Details

    • ProviderBase

      protected ProviderBase(MAPPER_CONFIG mconfig)
    • ProviderBase

      @Deprecated protected ProviderBase()
      Deprecated.
      Constructor that is only added to resolve problems with combination of RESTeasy and CDI. Should NOT be used by any code explicitly; only exists for proxy support.
    • ProviderBase

      protected ProviderBase(MAPPER_CONFIG mconfig, tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG> readerCache, tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG> writerCache)
      Since:
      2.17
  • Method Details

    • addUntouchable

      public void addUntouchable(Class<?> type)
      Method for marking specified type as "untouchable", meaning that provider will not try to read or write values of this type (or its subtypes).
      Parameters:
      type - Type to consider untouchable; can be any kind of class, including abstract class or interface. No instance of this type (including subtypes, i.e. types assignable to this type) will be read or written by provider
    • removeUntouchable

      public void removeUntouchable(Class<?> type)
      Method for removing definition of specified type as untouchable: usually only
    • setAnnotationsToUse

      public void setAnnotationsToUse(tools.jackson.databind.AnnotationIntrospector aiOverride)
      Method for overriding AnnotationIntrospector to use instead of default JacksonAnnotationIntrospector: often used to add JAXB-backed introspector.
      Parameters:
      aiOverride - AnnotationIntrospector to configure mapper to use (null to leave it as default one)
    • setMapper

      public void setMapper(MAPPER m)
      Method that can be used to directly define ObjectMapper to use for serialization and deserialization; if null, will use the standard provider discovery from context instead. Default setting is null.
    • setDefaultReadView

      public THIS setDefaultReadView(Class<?> view)
      Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.
    • setDefaultWriteView

      public THIS setDefaultWriteView(Class<?> view)
      Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.
    • setDefaultView

      public THIS setDefaultView(Class<?> view)
      Method for specifying JSON View to use for reading and writing content when end point does not have explicit View annotations. Functionally equivalent to: setDefaultReadView(view); setDefaultWriteView(view);
    • configure

      public THIS configure(JakartaRSFeature feature, boolean state)
    • enable

      public THIS enable(JakartaRSFeature feature)
    • enable

      public THIS enable(JakartaRSFeature first, JakartaRSFeature... f2)
    • disable

      public THIS disable(JakartaRSFeature feature)
    • disable

      public THIS disable(JakartaRSFeature first, JakartaRSFeature... f2)
    • isEnabled

      public boolean isEnabled(JakartaRSFeature f)
    • configure

      public THIS configure(tools.jackson.databind.DeserializationFeature f, boolean state)
    • enable

      public THIS enable(tools.jackson.databind.DeserializationFeature f)
    • disable

      public THIS disable(tools.jackson.databind.DeserializationFeature f)
    • configure

      public THIS configure(tools.jackson.databind.SerializationFeature f, boolean state)
    • enable

      public THIS enable(tools.jackson.databind.SerializationFeature f)
    • disable

      public THIS disable(tools.jackson.databind.SerializationFeature f)
    • hasMatchingMediaTypeForReading

      protected boolean hasMatchingMediaTypeForReading(jakarta.ws.rs.core.MediaType mediaType)
      Helper method used to check whether given media type is supported by this provider for read operations (when binding input data such as POST body).

      Default implementation simply calls hasMatchingMediaType(jakarta.ws.rs.core.MediaType).

    • hasMatchingMediaTypeForWriting

      protected boolean hasMatchingMediaTypeForWriting(jakarta.ws.rs.core.MediaType mediaType)
      Helper method used to check whether given media type is supported by this provider for writing operations, such as when converting response object to response body of request (like GET or POST).

      Default implementation simply calls hasMatchingMediaType(jakarta.ws.rs.core.MediaType).

    • hasMatchingMediaType

      protected abstract boolean hasMatchingMediaType(jakarta.ws.rs.core.MediaType mediaType)
      Helper method used to check whether given media type is supported by this provider.
    • _locateMapperViaProvider

      protected abstract MAPPER _locateMapperViaProvider(Class<?> type, jakarta.ws.rs.core.MediaType mediaType)
      Helper method that is called if no mapper has been explicitly configured.
    • _configForReading

      protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView)
    • _configForWriting

      protected EP_CONFIG _configForWriting(MAPPER mapper, Annotation[] annotations, Class<?> defaultView)
    • _configForReading

      protected abstract EP_CONFIG _configForReading(tools.jackson.databind.ObjectReader reader, Annotation[] annotations)
    • _configForWriting

      protected abstract EP_CONFIG _configForWriting(tools.jackson.databind.ObjectWriter writer, Annotation[] annotations)
    • getSize

      public long getSize(Object value, Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType)
      Method that Jakarta-RS container calls to try to figure out serialized length of given value. Since computation of this length is about as expensive as serialization itself, implementation will return -1 to denote "not known", so that container will determine length from actual serialized output (if needed).
      Specified by:
      getSize in interface jakarta.ws.rs.ext.MessageBodyWriter<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>>
    • isWriteable

      public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType)
      Method that Jakarta-RS container calls to try to check whether given value (of specified type) can be serialized by this provider. Implementation will first check that expected media type is expected one (by call to hasMatchingMediaType(jakarta.ws.rs.core.MediaType)); then verify that type is not one of "untouchable" types.

      NOTE: in 2.x also checked (if configured) for "canSerialize()", but with 3.x that is not done since there that detection never worked in a useful manner.

      Specified by:
      isWriteable in interface jakarta.ws.rs.ext.MessageBodyWriter<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>>
    • writeTo

      public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream) throws tools.jackson.core.JacksonException
      Method that Jakarta-RS container calls to serialize given value.
      Specified by:
      writeTo in interface jakarta.ws.rs.ext.MessageBodyWriter<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>>
      Throws:
      tools.jackson.core.JacksonException
    • findEncoding

      protected tools.jackson.core.JsonEncoding findEncoding(jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
      Helper method to use for determining desired output encoding. For now, will always just use UTF-8...
    • _modifyHeaders

      protected void _modifyHeaders(Object value, Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, EP_CONFIG endpoint) throws tools.jackson.core.JacksonException
      Overridable method used for adding optional response headers before serializing response object.
      Throws:
      tools.jackson.core.JacksonException
    • _createGenerator

      protected tools.jackson.core.JsonGenerator _createGenerator(tools.jackson.databind.ObjectWriter writer, OutputStream rawStream, tools.jackson.core.JsonEncoding enc) throws tools.jackson.core.JacksonException
      Overridable helper method called to create a JsonGenerator for writing contents into given raw OutputStream.
      Throws:
      tools.jackson.core.JacksonException
    • _endpointForWriting

      protected EP_CONFIG _endpointForWriting(Object value, Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
    • isReadable

      public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType)
      Method that Jakarta-RS container calls to try to check whether values of given type (and media type) can be deserialized by this provider. Implementation will first check that expected media type is a JSON type (via call to hasMatchingMediaType(jakarta.ws.rs.core.MediaType)); then verify that type is not one of "untouchable" types (types we will never automatically handle).

      NOTE: in 2.x also checked (if configured) for "canDeserialize()", but with 3.x that is not done since there that detection never worked in a useful manner.

      Specified by:
      isReadable in interface jakarta.ws.rs.ext.MessageBodyReader<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>>
    • readFrom

      public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,String> httpHeaders, InputStream entityStream) throws tools.jackson.core.JacksonException, jakarta.ws.rs.core.NoContentException
      Method that Jakarta-RS container calls to deserialize given value.
      Specified by:
      readFrom in interface jakarta.ws.rs.ext.MessageBodyReader<THIS extends ProviderBase<THIS,MAPPER,EP_CONFIG,MAPPER_CONFIG>>
      Throws:
      tools.jackson.core.JacksonException
      jakarta.ws.rs.core.NoContentException
    • _createParser

      protected tools.jackson.core.JsonParser _createParser(tools.jackson.databind.ObjectReader reader, InputStream rawStream) throws tools.jackson.core.JacksonException
      Overridable helper method called to create a JsonParser for reading contents of given raw InputStream. May return null to indicate that Stream is empty; that is, contains no content.
      Throws:
      tools.jackson.core.JacksonException
    • _endpointForReading

      protected EP_CONFIG _endpointForReading(Class<Object> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,String> httpHeaders)
      Overridable helper method that will basically fetch representation of the endpoint that can be used to get ObjectReader to use for deserializing content
    • locateMapper

      public MAPPER locateMapper(Class<?> type, jakarta.ws.rs.core.MediaType mediaType)
      Method called to locate ObjectMapper to use for serialization and deserialization. Exact logic depends on setting of JakartaRSFeature.DYNAMIC_OBJECT_MAPPER_LOOKUP.

      If JakartaRSFeature.DYNAMIC_OBJECT_MAPPER_LOOKUP is disabled (default setting unless changed), behavior is as follows:

      1. If an instance has been explicitly defined by setMapper(MAPPER) (or non-null instance passed in constructor), that will be used.
      2. If not, will try to locate it using standard Jakarta-RS ContextResolver mechanism, if it has been properly configured to access it (by Jakarta-RS runtime).
      3. Finally, if no mapper is found, will return a default unconfigured ObjectMapper instance (one constructed with default constructor and not modified in any way)

      If JakartaRSFeature.DYNAMIC_OBJECT_MAPPER_LOOKUP is enabled, steps 1 and 2 are reversed, such that Jakarta-RS ContextResolver is first used, and only if none is defined will configured mapper be used.

      Parameters:
      type - Class of object being serialized or deserialized; not checked at this point, since it is assumed that unprocessable classes have been already weeded out, but will be passed to ContextResolver as is.
      mediaType - Declared media type for the instance to process: not used by this method, but will be passed to ContextResolver as is.
    • _isSpecialReadable

      protected boolean _isSpecialReadable(Class<?> type)
      Overridable helper method used to allow handling of somewhat special types for reading
    • _isIgnorableForReading

      protected boolean _isIgnorableForReading(ClassKey typeKey)
      Overridable helper method called to check whether given type is a known "ignorable type" (in context of reading), values of which are not bound from content.
    • _isIgnorableForWriting

      protected boolean _isIgnorableForWriting(ClassKey typeKey)
      Overridable helper method called to check whether given type is a known "ignorable type" (in context of reading), values of which can not be written out.
    • _createNoContentException

      protected jakarta.ws.rs.core.NoContentException _createNoContentException()
    • _containedIn

      protected static boolean _containedIn(Class<?> mainType, HashSet<ClassKey> set)
    • _findCustomUntouchable

      protected Boolean _findCustomUntouchable(Class<?> mainType)
    • findSuperTypes

      protected static List<Class<?>> findSuperTypes(Class<?> cls, Class<?> endBefore)
    • findSuperTypes

      protected static List<Class<?>> findSuperTypes(Class<?> cls, Class<?> endBefore, List<Class<?>> result)
    • _addSuperTypes

      protected static void _addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself)