Search code examples
androidjsonjacksonobjectmappersigned-apk

Andiord signed apk : Jackson ObjectMapper returns null for an object containing List


My Rest API returns an instance of the following object in Json string format :

public class ObjectWithList implements Serializable {
    private long id;
    private String name;
    private List<String> contacts;
}

My Android app tries to deserialize this result using the following code :

ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(jsonResponse, ObjectWithList.class);

In debug apk, ObjectMapper is able to deserialize the JSON string into this object instance successfully and the list data is intact. However, in signed apk, the object returned contains empty list. Even the name is null. There are no exceptions from the ObjectMapper. Why isn't this working? Other APIs that return any other objects without any list get deserialized without any issues. Why are objects containing lists not working?

I checked many SO posts, but couldn't find any inputs to solve this problem. Any hints/pointers is greatly appreciated.

Regards, Shobhana


Solution

  • In debug apk, ObjectMapper is able to deserialize the JSON string into this object instance successfully and the list data is intact. However, in signed apk, the object returned contains empty list

    I suspect you are using ProGuard and by default it is disabled for debug builds. You may either disable it for your signed ones too by setting minifyEnabled false in your build.gradle or exclude certain classes from ProGuard.