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>>
- All Implemented Interfaces:
jakarta.ws.rs.ext.MessageBodyReader<Object>,jakarta.ws.rs.ext.MessageBodyWriter<Object>,tools.jackson.core.Versioned
-
Field Summary
FieldsModifier and TypeFieldDescriptionMap that contains overrides to default list of untouchable types:truemeaning that entry is untouchable,falsethat is is not.protected Class<?>View to use for reading if none defined for the end point.protected Class<?>View to use for writing if none defined for the end point.protected intFeature flags set.protected final MAPPER_CONFIGHelper object used for encapsulating configuration aspects ofObjectMapperprotected final tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG> Cache for resolved endpoint configurations when reading JSON datastatic final Class<?>[]static final Class<?>[]protected final tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG> Cache for resolved endpoint configurations when writing JSON datastatic final Class<?>[]These are classes that we never use for reading (never try to deserialize instances of these types).Looks like we need to worry about accidental data binding for types we shouldn't be handling.static final Class<?>[]These are classes that we never use for writing (never try to serialize instances of these types).static final StringThis header is useful on Windows, trying to deal with potential XSS attacks.protected static final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDeprecated.protectedProviderBase(MAPPER_CONFIG mconfig) protectedProviderBase(MAPPER_CONFIG mconfig, tools.jackson.databind.util.LookupCache<AnnotationBundleKey, EP_CONFIG> readerCache, tools.jackson.databind.util.LookupCache<AnnotationBundleKey, EP_CONFIG> writerCache) -
Method Summary
Modifier and TypeMethodDescriptionprotected static void_addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself) protected EP_CONFIG_configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) protected abstract EP_CONFIG_configForReading(tools.jackson.databind.ObjectReader reader, Annotation[] annotations) protected EP_CONFIG_configForWriting(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) protected abstract EP_CONFIG_configForWriting(tools.jackson.databind.ObjectWriter writer, Annotation[] annotations) protected static boolean_containedIn(Class<?> mainType, HashSet<ClassKey> set) protected tools.jackson.core.JsonGenerator_createGenerator(tools.jackson.databind.ObjectWriter writer, OutputStream rawStream, tools.jackson.core.JsonEncoding enc) Overridable helper method called to create aJsonGeneratorfor writing contents into given rawOutputStream.protected jakarta.ws.rs.core.NoContentExceptionprotected tools.jackson.core.JsonParser_createParser(tools.jackson.databind.ObjectReader reader, InputStream rawStream) Overridable helper method called to create aJsonParserfor reading contents of given rawInputStream.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 getObjectReaderto use for deserializing contentprotected 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) protected Boolean_findCustomUntouchable(Class<?> mainType) 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.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.protected boolean_isSpecialReadable(Class<?> type) Overridable helper method used to allow handling of somewhat special types for readingprotected abstract MAPPER_locateMapperViaProvider(Class<?> type, jakarta.ws.rs.core.MediaType mediaType) Helper method that is called if no mapper has been explicitly configured.protected void_modifyHeaders(Object value, Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, EP_CONFIG endpoint) Overridable method used for adding optional response headers before serializing response object.voidaddUntouchable(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).configure(tools.jackson.databind.DeserializationFeature f, boolean state) configure(tools.jackson.databind.SerializationFeature f, boolean state) configure(JakartaRSFeature feature, boolean state) disable(tools.jackson.databind.DeserializationFeature f) disable(tools.jackson.databind.SerializationFeature f) disable(JakartaRSFeature feature) disable(JakartaRSFeature first, JakartaRSFeature... f2) enable(tools.jackson.databind.DeserializationFeature f) enable(tools.jackson.databind.SerializationFeature f) enable(JakartaRSFeature feature) enable(JakartaRSFeature first, JakartaRSFeature... f2) protected tools.jackson.core.JsonEncodingfindEncoding(jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String, Object> httpHeaders) Helper method to use for determining desired output encoding.findSuperTypes(Class<?> cls, Class<?> endBefore) findSuperTypes(Class<?> cls, Class<?> endBefore, List<Class<?>> result) longgetSize(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.protected abstract booleanhasMatchingMediaType(jakarta.ws.rs.core.MediaType mediaType) Helper method used to check whether given media type is supported by this provider.protected booleanhasMatchingMediaTypeForReading(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).protected booleanhasMatchingMediaTypeForWriting(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).booleanbooleanisReadable(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.booleanisWriteable(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.locateMapper(Class<?> type, jakarta.ws.rs.core.MediaType mediaType) Method called to locateObjectMapperto use for serialization and deserialization.readFrom(Class<Object> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String, String> httpHeaders, InputStream entityStream) Method that Jakarta-RS container calls to deserialize given value.voidremoveUntouchable(Class<?> type) Method for removing definition of specified type as untouchable: usually onlyvoidsetAnnotationsToUse(tools.jackson.databind.AnnotationIntrospector aiOverride) Method for overridingAnnotationIntrospectorto use instead of defaultJacksonAnnotationIntrospector: often used to add JAXB-backed introspector.setDefaultReadView(Class<?> view) Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.setDefaultView(Class<?> view) Method for specifying JSON View to use for reading and writing content when end point does not have explicit View annotations.setDefaultWriteView(Class<?> view) Method for specifying JSON View to use for reading content when end point does not have explicit View annotations.voidMethod that can be used to directly defineObjectMapperto use for serialization and deserialization; if null, will use the standard provider discovery from context instead.voidwriteTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) Method that Jakarta-RS container calls to serialize given value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface tools.jackson.core.Versioned
version
-
Field Details
-
HEADER_CONTENT_TYPE_OPTIONS
This header is useful on Windows, trying to deal with potential XSS attacks.- See Also:
-
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
These are classes that we never use for reading (never try to deserialize instances of these types). -
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
Helper object used for encapsulating configuration aspects ofObjectMapper -
_cfgCustomUntouchables
Map that contains overrides to default list of untouchable types:truemeaning that entry is untouchable,falsethat is is not. -
_jakartaRSFeatures
protected int _jakartaRSFeaturesFeature flags set. -
_defaultReadView
View to use for reading if none defined for the end point. -
_defaultWriteView
View to use for writing if none defined for the end point. -
_untouchables
-
_unreadableClasses
-
_unwritableClasses
-
_readers
protected final tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG extends EndpointConfigBase<EP_CONFIG>> _readersCache for resolved endpoint configurations when reading JSON data -
_writers
protected final tools.jackson.databind.util.LookupCache<AnnotationBundleKey,EP_CONFIG extends EndpointConfigBase<EP_CONFIG>> _writersCache for resolved endpoint configurations when writing JSON data
-
-
Constructor Details
-
ProviderBase
-
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
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
Method for removing definition of specified type as untouchable: usually only -
setAnnotationsToUse
public void setAnnotationsToUse(tools.jackson.databind.AnnotationIntrospector aiOverride) Method for overridingAnnotationIntrospectorto use instead of defaultJacksonAnnotationIntrospector: often used to add JAXB-backed introspector.- Parameters:
aiOverride- AnnotationIntrospector to configure mapper to use (nullto leave it as default one)
-
setMapper
Method that can be used to directly defineObjectMapperto use for serialization and deserialization; if null, will use the standard provider discovery from context instead. Default setting is null. -
setDefaultReadView
Method for specifying JSON View to use for reading content when end point does not have explicit View annotations. -
setDefaultWriteView
Method for specifying JSON View to use for reading content when end point does not have explicit View annotations. -
setDefaultView
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
-
enable
-
enable
-
disable
-
disable
-
isEnabled
-
configure
-
enable
-
disable
-
configure
-
enable
-
disable
-
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:
getSizein interfacejakarta.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 tohasMatchingMediaType(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:
isWriteablein interfacejakarta.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.JacksonExceptionMethod that Jakarta-RS container calls to serialize given value.- Specified by:
writeToin interfacejakarta.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.JacksonExceptionOverridable 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 aJsonGeneratorfor writing contents into given rawOutputStream.- Throws:
tools.jackson.core.JacksonException
-
_endpointForWriting
-
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 tohasMatchingMediaType(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:
isReadablein interfacejakarta.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.NoContentExceptionMethod that Jakarta-RS container calls to deserialize given value.- Specified by:
readFromin interfacejakarta.ws.rs.ext.MessageBodyReader<THIS extends ProviderBase<THIS,MAPPER, EP_CONFIG, MAPPER_CONFIG>> - Throws:
tools.jackson.core.JacksonExceptionjakarta.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 aJsonParserfor reading contents of given rawInputStream. 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 getObjectReaderto use for deserializing content -
locateMapper
Method called to locateObjectMapperto use for serialization and deserialization. Exact logic depends on setting ofJakartaRSFeature.DYNAMIC_OBJECT_MAPPER_LOOKUP.If
JakartaRSFeature.DYNAMIC_OBJECT_MAPPER_LOOKUPis disabled (default setting unless changed), behavior is as follows:- If an instance has been explicitly defined by
setMapper(MAPPER)(or non-null instance passed in constructor), that will be used. - If not, will try to locate it using standard Jakarta-RS
ContextResolvermechanism, if it has been properly configured to access it (by Jakarta-RS runtime). - Finally, if no mapper is found, will return a default unconfigured
ObjectMapperinstance (one constructed with default constructor and not modified in any way)
If
JakartaRSFeature.DYNAMIC_OBJECT_MAPPER_LOOKUPis enabled, steps 1 and 2 are reversed, such that Jakarta-RSContextResolveris 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 toContextResolveras is.mediaType- Declared media type for the instance to process: not used by this method, but will be passed toContextResolveras is.
- If an instance has been explicitly defined by
-
_isSpecialReadable
Overridable helper method used to allow handling of somewhat special types for reading -
_isIgnorableForReading
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
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
-
_findCustomUntouchable
-
findSuperTypes
-
findSuperTypes
-
_addSuperTypes
protected static void _addSuperTypes(Class<?> cls, Class<?> endBefore, Collection<Class<?>> result, boolean addClassItself)
-