Package org.springframework.pulsar.core
Class DefaultSchemaResolver
java.lang.Object
org.springframework.pulsar.core.DefaultSchemaResolver
- All Implemented Interfaces:
SchemaResolver
Default schema resolver capable of handling basic message types.
Additional message types can be configured with
addCustomSchemaMapping(Class, Schema)
.
- Author:
- Soby Chacko, Alexander Preuß, Chris Bono, Aleksei Arsenev
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.pulsar.core.SchemaResolver
SchemaResolver.SchemaResolverCustomizer<T extends SchemaResolver>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.pulsar.client.api.Schema<?>
addCustomSchemaMapping
(Class<?> messageType, org.apache.pulsar.client.api.Schema<?> schema) Adds a custom mapping from message type to schema.Gets the currently registered custom mappings from message type to schema.protected org.apache.pulsar.client.api.Schema<?>
getCustomSchemaOrMaybeDefault
(Class<?> messageClass, boolean returnDefault) org.apache.pulsar.client.api.Schema<?>
removeCustomMapping
(Class<?> messageType) Removes the custom mapping from message type to schema.<T> Resolved<org.apache.pulsar.client.api.Schema<T>>
resolveSchema
(Class<?> messageClass, boolean returnDefault) Get the schema to use for a message type.<T> Resolved<org.apache.pulsar.client.api.Schema<T>>
resolveSchema
(org.apache.pulsar.common.schema.SchemaType schemaType, ResolvableType messageType) Get the schema to use given a schema type and a message type.void
setObjectMapper
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) void
usePulsarMessageAnnotations
(boolean usePulsarMessageAnnotations) Sets whether to inspect message classes for the@PulsarMessage
annotation during schema resolution.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.pulsar.core.SchemaResolver
resolveSchema, resolveSchema, resolveSchema
-
Constructor Details
-
DefaultSchemaResolver
public DefaultSchemaResolver()
-
-
Method Details
-
setObjectMapper
public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
usePulsarMessageAnnotations
public void usePulsarMessageAnnotations(boolean usePulsarMessageAnnotations) Sets whether to inspect message classes for the@PulsarMessage
annotation during schema resolution.- Parameters:
usePulsarMessageAnnotations
- whether to inspect messages for the annotation
-
addCustomSchemaMapping
@Nullable public org.apache.pulsar.client.api.Schema<?> addCustomSchemaMapping(Class<?> messageType, org.apache.pulsar.client.api.Schema<?> schema) Adds a custom mapping from message type to schema.- Parameters:
messageType
- the message typeschema
- the schema to use for messages of typemessageType
- Returns:
- the previously mapped schema or
null
if there was no mapping formessageType
.
-
removeCustomMapping
Removes the custom mapping from message type to schema.- Parameters:
messageType
- the message type- Returns:
- the previously mapped schema or
null
if there was no mapping formessageType
.
-
getCustomSchemaMappings
Gets the currently registered custom mappings from message type to schema.- Returns:
- unmodifiable map of custom mappings
-
resolveSchema
public <T> Resolved<org.apache.pulsar.client.api.Schema<T>> resolveSchema(@Nullable Class<?> messageClass, boolean returnDefault) Description copied from interface:SchemaResolver
Get the schema to use for a message type.- Specified by:
resolveSchema
in interfaceSchemaResolver
- Type Parameters:
T
- the schema type- Parameters:
messageClass
- the message typereturnDefault
- whether to return default schema if no schema could be resolved- Returns:
- the schema to use or the default schema if no schema could be resolved and
returnDefault
istrue
- otherwisenull
-
getCustomSchemaOrMaybeDefault
-
resolveSchema
public <T> Resolved<org.apache.pulsar.client.api.Schema<T>> resolveSchema(org.apache.pulsar.common.schema.SchemaType schemaType, @Nullable ResolvableType messageType) Description copied from interface:SchemaResolver
Get the schema to use given a schema type and a message type.- Specified by:
resolveSchema
in interfaceSchemaResolver
- Type Parameters:
T
- the schema type- Parameters:
schemaType
- the schema typemessageType
- the message type- Returns:
- the schema to use
-