Class ProviderBase<THIS extends ProviderBase<THIS,​MAPPER,​EP_CONFIG,​MAPPER_CONFIG>,​MAPPER extends ObjectMapper,​EP_CONFIG extends EndpointConfigBase<EP_CONFIG>,​MAPPER_CONFIG extends MapperConfiguratorBase<MAPPER_CONFIG,​MAPPER>>

    • Field Detail

      • 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:
        Constant Field Values
      • 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
      • _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.
      • _cfgCheckCanSerialize

        protected boolean _cfgCheckCanSerialize
        Whether we want to actually check that Jackson has a serializer for given type. Since this should generally be the case (due to auto-discovery) and since the call to check availability can be bit expensive, defaults to false.
      • _cfgCheckCanDeserialize

        protected boolean _cfgCheckCanDeserialize
        Whether we want to actually check that Jackson has a deserializer for given type. Since this should generally be the case (due to auto-discovery) and since the call to check availability can be bit expensive, defaults to false.
      • _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.
      • _unreadableClasses

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

        public static final Class<?>[] _unwritableClasses
    • Constructor Detail

      • 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.
    • Method Detail

      • 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​(Annotations[] annotationsToUse)
        Method for configuring which annotation sets to use (including none). Annotation sets are defined in order decreasing precedence; that is, first one has the priority over following ones.
        Parameters:
        annotationsToUse - Ordered list of annotation sets to use; if null, default
      • 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);
      • hasMatchingMediaTypeForReading

        protected boolean hasMatchingMediaTypeForReading​(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​(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​(MediaType mediaType)
        Helper method used to check whether given media type is supported by this provider.
      • _locateMapperViaProvider

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

        public long getSize​(Object value,
                            Class<?> type,
                            Type genericType,
                            Annotation[] annotations,
                            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 MessageBodyWriter<THIS extends ProviderBase<THIS,​MAPPER,​EP_CONFIG,​MAPPER_CONFIG>>
        Parameters:
        value - the instance to write
        type - the class of instance that is to be written.
        genericType - the type of instance to be written. GenericEntity provides a way to specify this information at runtime.
        annotations - an array of the annotations attached to the message entity instance.
        mediaType - the media type of the HTTP entity.
        Returns:
        length in bytes or -1 if the length cannot be determined in advance.
      • isWriteable

        public boolean isWriteable​(Class<?> type,
                                   Type genericType,
                                   Annotation[] annotations,
                                   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 (types we will never automatically handle), and finally that there is a serializer for type (iff checkCanSerialize(boolean) has been called with true argument -- otherwise assumption is there will be a handler)
        Specified by:
        isWriteable in interface MessageBodyWriter<THIS extends ProviderBase<THIS,​MAPPER,​EP_CONFIG,​MAPPER_CONFIG>>
        Parameters:
        type - the class of instance that is to be written.
        genericType - the type of instance to be written, obtained either by reflection of a resource method return type or via inspection of the returned instance. GenericEntity provides a way to specify this information at runtime.
        annotations - an array of the annotations attached to the message entity instance.
        mediaType - the media type of the HTTP entity.
        Returns:
        true if the type is supported, otherwise false.
      • writeTo

        public void writeTo​(Object value,
                            Class<?> type,
                            Type genericType,
                            Annotation[] annotations,
                            MediaType mediaType,
                            MultivaluedMap<String,​Object> httpHeaders,
                            OutputStream entityStream)
                     throws IOException
        Method that Jakarta-RS container calls to serialize given value.
        Specified by:
        writeTo in interface MessageBodyWriter<THIS extends ProviderBase<THIS,​MAPPER,​EP_CONFIG,​MAPPER_CONFIG>>
        Parameters:
        value - the instance to write.
        type - the class of instance that is to be written.
        genericType - the type of instance to be written. GenericEntity provides a way to specify this information at runtime.
        annotations - an array of the annotations attached to the message entity instance.
        mediaType - the media type of the HTTP entity.
        httpHeaders - a mutable map of the HTTP message headers.
        entityStream - the OutputStream for the HTTP entity. The implementation must not close the output stream.
        Throws:
        IOException - if an IO error arises.
      • isReadable

        public boolean isReadable​(Class<?> type,
                                  Type genericType,
                                  Annotation[] annotations,
                                  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), and finally that there is a deserializer for type (iff checkCanDeserialize(boolean) has been called with true argument -- otherwise assumption is there will be a handler)
        Specified by:
        isReadable in interface MessageBodyReader<THIS extends ProviderBase<THIS,​MAPPER,​EP_CONFIG,​MAPPER_CONFIG>>
        Parameters:
        type - the class of instance to be produced.
        genericType - the type of instance to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Method.getGenericParameterTypes.
        annotations - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations.
        mediaType - the media type of the HTTP entity, if one is not specified in the request then application/octet-stream is used.
        Returns:
        true if the type is supported, otherwise false.
      • readFrom

        public Object readFrom​(Class<Object> type,
                               Type genericType,
                               Annotation[] annotations,
                               MediaType mediaType,
                               MultivaluedMap<String,​String> httpHeaders,
                               InputStream entityStream)
                        throws IOException
        Method that Jakarta-RS container calls to deserialize given value.
        Specified by:
        readFrom in interface MessageBodyReader<THIS extends ProviderBase<THIS,​MAPPER,​EP_CONFIG,​MAPPER_CONFIG>>
        Parameters:
        type - the type that is to be read from the entity stream.
        genericType - the type of instance to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Method.getGenericParameterTypes.
        annotations - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations.
        mediaType - the media type of the HTTP entity.
        httpHeaders - the read-only HTTP headers associated with HTTP entity.
        entityStream - the InputStream of the HTTP entity. The caller is responsible for ensuring that the input stream ends when the entity has been consumed. The implementation should not close the input stream.
        Returns:
        the type that was read from the stream. In case the entity input stream is empty, the reader is expected to either return an instance representing a zero-length entity or throw a NoContentException in case no zero-length entity representation is defined for the supported Java type.
        Throws:
        IOException - if an IO error arises. In case the entity input stream is empty and the reader is not able to produce a Java representation for a zero-length entity, NoContentException is expected to be thrown.
      • locateMapper

        public MAPPER locateMapper​(Class<?> type,
                                   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
        Since:
        2.2
      • _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 IOException _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)
      • _addSuperTypes

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