Class DefaultSchemaResolver

java.lang.Object
org.springframework.pulsar.core.DefaultSchemaResolver
All Implemented Interfaces:
SchemaResolver

public class DefaultSchemaResolver extends Object implements 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
  • Constructor Details

    • DefaultSchemaResolver

      public DefaultSchemaResolver()
  • Method Details

    • 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 type
      schema - the schema to use for messages of type messageType
      Returns:
      the previously mapped schema or null if there was no mapping for messageType.
    • removeCustomMapping

      @Nullable public org.apache.pulsar.client.api.Schema<?> removeCustomMapping(Class<?> messageType)
      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 for messageType.
    • getCustomSchemaMappings

      public Map<Class<?>,org.apache.pulsar.client.api.Schema<?>> 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 interface SchemaResolver
      Type Parameters:
      T - the schema type
      Parameters:
      messageClass - the message type
      returnDefault - 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 is true - otherwise null
    • getCustomSchemaOrMaybeDefault

      @Nullable protected org.apache.pulsar.client.api.Schema<?> getCustomSchemaOrMaybeDefault(@Nullable Class<?> messageClass, boolean returnDefault)
    • 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 interface SchemaResolver
      Type Parameters:
      T - the schema type
      Parameters:
      schemaType - the schema type
      messageType - the message type
      Returns:
      the schema to use