繁体   English   中英

Quarkus Kafka Reactive - 反序列化子类(错误)

[英]Quarkus Kafka Reactive - Deserializing SubClass (ERROR)

我正在使用 Quarkus 接收来自 Kafka 的消息。

当我只使用一个 class 的方法时,反序列化正常进行。 当我的 class 被子类化时,我无法继续反序列化并出现错误。

我在控制台 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}

我的方法。

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

我反序列化 class

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

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

我的 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();
    }
}

}

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() {}
}

错误:

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 (尽管至少存在一个 Creator):没有字符串参数构造函数/工厂方法可以从字符串值反序列化('{"idCard": 2,"balance": 456,"pin":222}')

我按照以下教程进行操作: https://quarkus.io/guides/kafka#kafka-serialization

有没有人遇到过这个问题?

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. 尝试更改序列化数据的方式,以便将有效负载序列化为 object。

很抱歉将此作为回复发布,我没有足够的声誉来发表评论。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM