0

class java.util.ArrayList cannot be cast to class org.apache.avro.specific.SpecificRecord (java.util.ArrayList is in module java.base of loader 'bootstrap'; org.apache.avro.specific.SpecificRecord is in unnamed module of loader 'app')

another issue org.apache.kafka.streams.errors.StreamsException: Error encountered sending record to topic structure-KTABLE-AGGREGATE-STATE-STORE-0000000015-repartition for task 2_0 due to: org.apache.kafka.common.errors.SerializationException: Error serializing Avro message

final KTable<String, ArrayList<Employee>> caKTables = caKTable
    .groupBy((key, value) -> pair(value.getBrStId(), value))
    .aggregate((Initializer<ArrayList<Employee>>) ArrayList::new, (key, value, aggregate) -> {
        aggregate.add(value);
        return aggregate;
    }, (key, oldValue, agg) -> {
        agg.remove(oldValue);
        return agg;
    });

            brKTable
            .leftJoin(caKTables, caJoiner) // TODO
            .toStream()
            .filter((key, value) -> value != null)
            .map(this::changeKey);
  • Can you please provide more information? What is caKTable? Which SERDE you are using (I am assuming Avro)?Are you using Schema Registry as well? Which build system you are using (may be your library is not included properly in the dependency)? – deadzg_devil Aug 25 '22 at 10:53
  • You will need to write your own `EmployeeListSerde`, for example, and add `Produced.with` and/or `Materialized.with` parameters here since there is the ListSerde class only supports primitive Java types, I believe – OneCricketeer Aug 25 '22 at 15:44
  • @deadzg_devil Yes i am using Schema Registry and Avro, i have added dependency org.springframework.cloud:spring-cloud-stream-binder-kafka-streams, io.confluent:kafka-avro-serializer:5.2.0, io.confluent:kafka-streams-avro-serde:5.2.0 – Pankaj Mandale Aug 25 '22 at 17:07
  • @OneCricketeer i have use Grouped.with(Serdes.String(), new SpecificAvroSerde<>()) but now i am facing another issue and how to write EmployeeListSerde – Pankaj Mandale Aug 25 '22 at 17:15
  • `Grouped.with` is for `groupBy` opertator. You need `Materialized.with` argument for the `aggregate` method... `SpecificAvroSerde` may work for one Employee class, but not a list of them. You'd start by creating a class that [`implements Serde`](https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/serialization/Serde.java). It may help if you actually create an Avro type the defines an `EmployeeList` with `type: array` – OneCricketeer Aug 26 '22 at 17:40

0 Answers0