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

Android using MSGPack Core and Jackson Mapper - decode class variable of unknown type

我是 sending/receiving 从服务器到 Android 的自定义 class,class 是;

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"]

如果我将变量 "data" 更改为 MAP<String, String> data 那么它工作正常,但是,数据是未知类型! (通常 HashMap 或数组可能是字符串,而不是其他 class)。

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;

}

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

org.msgpack.value.Value是一个接口。

当您使用 ObjectMapper 为 de-serializing 值时,目标必须是具有默认构造函数的 Class。否则明智的 OM 无法创建目标对象。