gpt4 book ai didi

使用 MSGPack Core 和 Jackson Mapper 的 Android - 解码未知类型的类变量

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:09:02 26 4
gpt4 key购买 nike

我正在从服务器向 Android 发送/接收自定义类,该类如下;

import org.msgpack.value.Value;
public class myClass {

public String status;
public Value data;

}

问题是我总是得到错误;

com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.msgpack.value.Value, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
at [Source: java.io.BufferedInputStream@f478759; line: -1, column: 100] (through reference chain:xxx.xxxxxxxxxx.xxx.xxxxxx.myClass["data"]

如果我将变量“数据”更改为 MAP<String, String> data然后它工作正常,但是,数据是未知类型! (通常 HashMap 或 Array 可能是 String,而不是其他类)。

MessagePackFactory factory = new MessagePackFactory();
ObjectMapper mapper = new ObjectMapper(factory);
myClass response = mapper.readValue(inputStream, myClass.class);

如何指定未知类型?

最佳答案

所以我把类(class)改成了;

public class myClass{

public String status;
public Object data;

}

我现在只测试对象类型。我不确定为什么我以前没有尝试过这个!

关于使用 MSGPack Core 和 Jackson Mapper 的 Android - 解码未知类型的类变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34316893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com