Skip to content

AvroItemWriter uses GenericDatumWriter instead of SpecificDatumWriter for type that extends SpecificRecordBase #3859

Closed
@adrianbielewicz

Description

@adrianbielewicz

Bug description
I am generating Java code from an Avro schema. It creates classes that extend SpecificRecordBase. In this case AvroItemWriter automatically chooses GenericDatumWriter as the underlying writer. This causes multiple exceptions when logical types are used in the schema (for example decimal or timestamp-millis).

It would work perfectly if SpecificDatumWriter is used. I believe that the problem lies in the order in which datum writer is chosen. The code checks first if my item class is an instance of GenericRecord and only after that returns false, it check if it is an instance of SpecificRecordBase. As SpecificRecordBase implements GenericRecord the first check will always return true and this leads to GenericDatumWriter to be used.

Environment
Spring Batch 4.3.1

Steps to reproduce

  1. Create a simple schema that uses logical types like decimal and timestamp-millis.
  2. Generate java code using avro-tools.
  3. Try to write using the generated classes.

Expected behavior
SpecificDatumWriter should be used instead of GenericDatumWriter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions