I have a problem deserialising messages which have been posted to a Kafka topic. I'm using spring-boot, spring cloud stream, apache kafka, and apache avro. The object I am trying to deserialise has a constructor which takes in two args. I am getting an exception when taking a message from the topic:
org.springframework.messaging.MessagingException: Exception thrown while invoking com.foo.bar.messaging.ResponseListener#handleResponse[1 args];
nested exception is java.lang.RuntimeException: java.lang.NoSuchMethodException: com.foo.bar.TheObject.<init>() at org.springframework.cloud.stream.binding.StreamListenerMessageHandler.handleRequestMessage(StreamListenerMessageHandler.java:63) ~[spring-cloud-stream-2.0.1.RELEASE.jar:2.0.1.RELEASE]
The class which is being deserialised has a constructor which takes 2 args, and looks like this:
public class TheObject {
private final int thingOne;
private final int thingTwo;
@JsonCreator
public TheObject(@JsonProperty("thingOne") int thingOne, @JsonProperty("thingTwo") int thingTwo) {
this.thingOne = thingOne;
this.thingTwo = thingTwo;
}
}
Previously I used Jackson, and just posted Strings to the kafka topic, so the @JsonCreator
annotation was enough to tell the mapper how to construct the object, but I'm now changing to use Arvo. Jackson is no longer used at all for this serialisation. I have left the annotations on the example above to show how it used to work.
In terms of configuration, I am using a property: dynamicSchemaGenerationEnabled: true
and not explicitly declaring object schemas. This seems to be working fine with both the spring Schema Registry, and Confluent Schema Registry (apart from the problem described here)
Is there an equivalent to the @JsonCreator
annotation that will work with the Arvo deserialisation?
thanks