Quarkus Kafka Reactive - Deserializing SubClass (ERROR)

Viewed 348

I am using Quarkus to receive messages from Kafka.

When I use the method with just one class, deserialization happens normally. When my class is subclassed, I can't continue with the deserialization and an error occurs.

My Input in console kafka:

{"id":"73707ad2-0732-4592-b7e2-79b07c745e45","currentstep":"Debit-approval","payload": "{\"idCard\": 2,\"balance\": 456,\"pin\":222}","sagastatus": "STARTED","stepstatus": "{\"credit-approval\":\"STARTED\"}","type":"order-placement","version": 1}

My Method.

@Incoming("process-transaction-in")
    public void process(TransactionModel transaction) throws InterruptedException { }

my deserialize class

import io.quarkus.kafka.client.serialization.ObjectMapperDeserializer;

public class TransactionDeserializer extends ObjectMapperDeserializer<TransactionModel> {
    public TransactionDeserializer() {
        super(TransactionModel.class);
    }

My class Model

public class TransactionModel {

    public TransactionModel(String id,
                            String currentStep,
                            PayloadModel payload,
                            String sagaStatus,
                            String stepStatus,
                            String type,
                            String version) {
        this.id = id;
        this.currentStep = currentStep;
        this.payload = payload;
        this.sagaStatus = sagaStatus;
        this.stepStatus = stepStatus;
        this.type = type;
        this.version = version;
    }

    public String id;
    public String currentStep;
    public PayloadModel payload;
    public String sagaStatus;
    public String stepStatus;
    public String type;
    public String version;

    public TransactionModel() {
         payload = new PayloadModel();
    }
}

}

The Class PayloadModel

public class PayloadModel {

    public PayloadModel(String idCard,
                        String current,
                        String pin) 
    {
        this.idCard = idCard;
        this.current = current;
        this.pin = pin;    
    }

    public String idCard;
    public String current;
    public String pin;
    

    public PayloadModel() {}
}

Error:

SRMSG18249: Unable to recover from the deserialization failure (topic: process-transaction), configure a DeserializationFailureHandler to recover from errors.: java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of payment.model.PayloadModel (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('{"idCard": 2,"balance": 456,"pin":222}')

I followed the following tutorial: https://quarkus.io/guides/kafka#kafka-serialization

Has anyone experienced this problem?

1 Answers

As you can see in the error log Jackson finds at least one constructor for PayloadModel class but it's not the one it's expecting since the "payload" parameter in your Kafka payload is a string and not a JSON Object. Try to change the way you serialize your data so that payload is serialized as an object.

Sorry for posting this as a response I don't have enough reputation to comment.

Related