Class SerdeProperties

    • Field Detail

      • EXPLICIT_SCHEMA_ID

        public static final String EXPLICIT_SCHEMA_ID
        Property key for setting an explicit schema ID to be used during serialization. Not used in deserialization.

        This property allows overriding the schema ID provided by the schema registry. When set, the serializer will use this explicit schema ID instead of the one obtained from the registry.

        The value should be a non-negative Number or a String that can be parsed as a non-negative long (0 or positive). If set to a negative Number or unparsable String, AbstractSerializer.configure(java.util.Map) will throw an IllegalStateException.

        If this property is not set or is set to null, the serializer will use the schema ID provided by the schema registry.

        Example usage:

         // Using a Number
         properties.put(EXPLICIT_SCHEMA_ID, 42L);
        
         // Using a String
         properties.put(EXPLICIT_SCHEMA_ID, "42");
         
        See Also:
        Constant Field Values
      • SCHEMA_RESOLVER

        public static final String SCHEMA_RESOLVER
        Property key for specifying a custom schema resolver implementation.

        This property allows the user to provide a custom implementation of the SchemaResolver interface, which is responsible for resolving schema information during serialization and deserialization processes.

        The value associated with this key should be either:

        • A String of a qualified class name of a class implementing the SchemaResolver interface
        • An Class object of a class implementing the SchemaResolver interface

        Make sure the target class must have a public no-argument constructor.

        Example usage. All these will have equivalent functionality.

         // Using a class name
         properties.put(SCHEMA_RESOLVER, "com.example.CustomSchemaResolver");
        
         // Using an Class object
         properties.put(SCHEMA_RESOLVER, CustomSchemaResolver.class);
         

        The specified schema resolver will be used for all schema resolution operations, potentially overriding the default behavior of schema lookup and caching.

        See Also:
        SchemaResolver, Constant Field Values
      • DESERIALIZED_TYPE

        public static final String DESERIALIZED_TYPE
        An optional property when set explicitly checks if the deserialized type matches this property.

        The value associated with this key should be either:

        • null when no checking is wanted (Default)
        • A String of a qualified class name of a class implementing the SpecificRecord interface
        • An Class object of a class implementing the SchemaResolver interface

        Example usage. All these will have equivalent functionality.

         // Using a class name
         properties.put(DESERIALIZED_TYPE, "com.example.CustomSpecificRecord");
        
         // Using an Class object
         properties.put(DESERIALIZED_TYPE, CustomSpecificRecord.class);
         
        See Also:
        Constant Field Values
      • SCHEMA_HEADER_IDENTIFIERS

        public static final String SCHEMA_HEADER_IDENTIFIERS
        Property key for setting one or more schema header identifiers to be encoded in the serializer headers.

        NOTE: This property has no impact on deserializers.

        The value associated with this key should be either:

        The default value is set to: SchemaHeaderId.SCHEMA_ID.

        Example usage:

         // Using a String for a single identifier
         properties.put(SCHEMA_HEADER_IDENTIFIERS, "SCHEMA_ID_STRING");
        
         // Using an Enum constant for a single identifier
         properties.put(SCHEMA_HEADER_IDENTIFIERS, SchemaHeaderId.SCHEMA_ID_STRING);
        
         // Using an EnumSet for multiple identifiers
         properties.put(SCHEMA_HEADER_IDENTIFIERS, EnumSet.of(SchemaHeaderId.SCHEMA_ID, SchemaHeaderId.SCHEMA_ID_STRING));
         
        See Also:
        SchemaHeaderId, Constant Field Values
    • Constructor Detail

      • SerdeProperties

        public SerdeProperties()
        Constructs a new SerdeProperties instance with default properties.
      • SerdeProperties

        public SerdeProperties​(Map<String,​?> map)
        Constructs a new SerdeProperties instance with default properties then applies properties from the passed in map.
        Parameters:
        map - A map that is applied after the default properties are applied.
    • Method Detail

      • getDefaults

        public static Map<String,​Object> getDefaults()
        Gets a copy of the default SERDE properties.
        Returns:
        The default set properties.
      • getExplicitSchemaId

        public Optional<Long> getExplicitSchemaId()
        Gets the Explicit SchemeId.
        Returns:
        An Optional containing the explicit schema ID if it was set, or an empty Optional if no explicit schema ID was provided.
        Throws:
        IllegalStateException - when the key SerdeProperties.EXPLICIT_SCHEMA_ID matches one of the following cases:
        1. The value is not a String or a Number
        2. The value is a String, but is not parsable as a long
        3. The value is negative.
      • getSchemaResolverClass

        public Class<?> getSchemaResolverClass()
        Retrieves a SchemaResolver for the specified schema type.

        This method attempts to get an instance of a SchemaResolver that can handle the given schema type.

        The SCHEMA_RESOLVER key in the configuration can be:

        • A fully qualified class name (String) of a SchemaResolver implementation
        • A Class object of a SchemaResolver implementation
        Returns:
        A SchemaResolver instance that can handle the specified schema type.
        Throws:
        IllegalStateException - if:
        • No SchemaResolver is found for the SCHEMA_RESOLVER key
        • The class specified by the SCHEMA_RESOLVER key is not found
        • The object specified by the SCHEMA_RESOLVER key is neither a String, nor Class
        See Also:
        SchemaResolver
      • getDeserializedType

        public Class<?> getDeserializedType()
        Retrieves the expected Deserialized type as specified in the configuration. Returns null when not set.

        This method gets the Deserialized type that was configured using the DESERIALIZED_TYPE property.

        The DESERIALIZED_TYPE key in the configuration can be:

        • null when no checking is wanted (Default)
        • A fully qualified class name (String) of a SpecificRecord implementation
        • A Class object of a SpecificRecord implementation
        Returns:
        The Class object of the configured deserialized type.
        Throws:
        IllegalStateException - if:
        • The class specified by the DESERIALIZED_TYPE key is not found
        • The object specified by the DESERIALIZED_TYPE key is neither a String, nor Class
      • getSchemaHeaderIdentifiers

        public Set<SchemaHeaderId> getSchemaHeaderIdentifiers()
        Retrieves the schema header identifiers as specified in the configuration.

        This method gets the schema header identifiers that were configured using the SCHEMA_HEADER_IDENTIFIERS property.

        The SCHEMA_HEADER_IDENTIFIERS key in the configuration can be:

        Returns:
        The set of schema header identifiers.
        Throws:
        IllegalStateException - if the value associated with the key is null or of an incompatible type.
        See Also:
        SCHEMA_HEADER_IDENTIFIERS