Jackson: deserialization of Map Jackson: deserialization of Map json json

Jackson: deserialization of Map


public class ArrayMapDeserializer extends JsonDeserializer<Map<String, UUIDInfo>> {    @Override    public Map<String, UUIDInfo> deserialize(JsonParser jp, DeserializationContext context)            throws IOException {        ObjectMapper mapper = (ObjectMapper) jp.getCodec();        if (jp.getCurrentToken().equals(JsonToken.START_OBJECT)) {            return mapper.readValue(jp, new TypeReference<HashMap<String, UUIDInfo>>() {            });        } else {            //consume this stream            mapper.readTree(jp);            return new HashMap<String, UUIDInfo>();        }    }}

in class declare

@JsonDeserialize(using = ArrayMapDeserializer.class)private HashMap<String, UUIDInfo> aliases = new HashMap<String, UUIDInfo>();

I am using Jackson 2.4.2.

Hope it can help you.


Do it like this:

ArrayList<LinkedHashMap<?, ?>> companymap = mapper.readValue(jsonCompany, ArrayList.class);


I think the issue is one listed under 5.5 on Jackson polymorphic deserialization Wiki page.Basically it's the Java Type Erasure biting you when serializing; and when deserializing type is made available explicitly; and that discrepancy hurts.