Class AvroSchemaMessageConverter

java.lang.Object
org.springframework.messaging.converter.AbstractMessageConverter
org.springframework.cloud.function.context.converter.avro.AbstractAvroMessageConverter
org.springframework.cloud.function.context.converter.avro.AvroSchemaMessageConverter
All Implemented Interfaces:
org.springframework.messaging.converter.MessageConverter, org.springframework.messaging.converter.SmartMessageConverter

public class AvroSchemaMessageConverter extends AbstractAvroMessageConverter
A MessageConverter using Apache Avro. The schema for serializing and deserializing will be automatically inferred from the class for SpecificRecord and regular classes, unless a specific schema is set, case in which that schema will be used instead. For converting to GenericRecord targets, a schema must be set.s
Since:
3.2.0
Author:
Marius Bogoevici, Ish Mahajan, Soby Chacko
  • Constructor Details

    • AvroSchemaMessageConverter

      public AvroSchemaMessageConverter(AvroSchemaServiceManager manager)
      Create a AvroSchemaMessageConverter. Uses the default MimeType of "application/avro".
      Parameters:
      manager - for schema management
    • AvroSchemaMessageConverter

      public AvroSchemaMessageConverter(org.springframework.util.MimeType supportedMimeType, AvroSchemaServiceManager manager)
      Create a AvroSchemaMessageConverter. The converter will be used for the provided MimeType.
      Parameters:
      supportedMimeType - mime type to be supported by AvroSchemaMessageConverter
      manager - for schema management
    • AvroSchemaMessageConverter

      public AvroSchemaMessageConverter(Collection<org.springframework.util.MimeType> supportedMimeTypes, AvroSchemaServiceManager manager)
      Create a AvroSchemaMessageConverter. The converter will be used for the provided MimeTypes.
      Parameters:
      supportedMimeTypes - the mime types supported by this converter
      manager - for schema management
  • Method Details

    • getSchema

      public org.apache.avro.Schema getSchema()
    • setSchema

      public void setSchema(org.apache.avro.Schema schema)
      Sets the Apache Avro schema to be used by this converter.
      Parameters:
      schema - schema to be used by this converter
    • setSchemaLocation

      public void setSchemaLocation(org.springframework.core.io.Resource schemaLocation)
      The location of the Apache Avro schema to be used by this converter.
      Parameters:
      schemaLocation - the location of the schema used by this converter.
    • supports

      protected boolean supports(Class<?> clazz)
      Specified by:
      supports in class org.springframework.messaging.converter.AbstractMessageConverter
    • resolveWriterSchemaForDeserialization

      protected org.apache.avro.Schema resolveWriterSchemaForDeserialization(org.springframework.util.MimeType mimeType)
      Specified by:
      resolveWriterSchemaForDeserialization in class AbstractAvroMessageConverter
    • resolveReaderSchemaForDeserialization

      protected org.apache.avro.Schema resolveReaderSchemaForDeserialization(Class<?> targetClass)
      Specified by:
      resolveReaderSchemaForDeserialization in class AbstractAvroMessageConverter
    • resolveSchemaForWriting

      protected org.apache.avro.Schema resolveSchemaForWriting(Object payload, org.springframework.messaging.MessageHeaders headers, org.springframework.util.MimeType hintedContentType)
      Specified by:
      resolveSchemaForWriting in class AbstractAvroMessageConverter