Rec*_*eel 6 android json class jackson msgpack
我正在从服务器向Android发送/接收自定义类,该类为;
import org.msgpack.value.Value;
public class myClass {
public String status;
public Value data;
}
Run Code Online (Sandbox Code Playgroud)
问题是我总是得到错误;
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"]
Run Code Online (Sandbox Code Playgroud)
如果我改变变量"data" MAP<String, String> data
然后它工作正常,但数据是未知类型!(通常HashMap或数组可能是String,而不是其他类).
MessagePackFactory factory = new MessagePackFactory();
ObjectMapper mapper = new ObjectMapper(factory);
myClass response = mapper.readValue(inputStream, myClass.class);
Run Code Online (Sandbox Code Playgroud)
如何指定未知类型?
所以我把课程改为;
public class myClass{
public String status;
public Object data;
}
Run Code Online (Sandbox Code Playgroud)
我现在只是测试对象类型。我不知道为什么我以前没有尝试过这个!