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

I send / receive a custom class from a server on Android, the class is like this:

import org.msgpack.value.Value; public class myClass { public String status; public Value data; } 

The problem is that I always get an error;

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

If I change the data variable to say MAP<String, String> data , then it works fine, however the data is of an unknown type! (well, usually a HashMap or Array, possibly a String, not some other class).

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

How to specify an unknown type?

+6
source share
2 answers

So, I changed the class to;

 public class myClass{ public String status; public Object data; } 

And now I'm just checking the type of the object. Iโ€™m not sure why I didnโ€™t do this before!

+2
source

org.msgpack.value.Value is an interface.

When you de-serialize values โ€‹โ€‹using ObjectMapper, the target should be a class with a default constructor. Another wise OM cannot create the target.

+1
source

All Articles