0

I have a very weird bug.

In my Android app, I deserialize an object stored in the user preferences using :

Type type = new TypeToken<ArrayList<CodableObject>>() {}.getType(); // Line 1
ArrayList<CodableObject> codableObjects = gson.fromJson(json, type); // Line 2

Everything works very well when I compile my app in debug mode, but when I compile it in release mode, I get the following error on Line 2:

IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at line 1 column 73366 path $[0].e.n

Why do I have a crash in release mode and not in debug mode ??? How to solve/debug this problem ?

Thanks for your help !

Tenfour04
  • 83,111
  • 11
  • 94
  • 154
toto_tata
  • 14,526
  • 27
  • 108
  • 198
  • First check that release mode obfuscation does not mess up your gson class. Add `@SerializedName` annotations or `@Keep` / `-keep` rules as necessary. – laalto Feb 01 '22 at 21:07
  • Thanks. Indeed, it is almost certain that it is the problem. So you have any recommendation about where to put these annotations ? I see many different strategies for example here: https://stackoverflow.com/questions/31844352/using-gson-with-proguard-enabled Will see that on tomorrow, too late here to work on these crazy Android bugs! Will read your answer with attention. Thanks a lot. – toto_tata Feb 01 '22 at 21:16
  • I'd have `@SerializedName` on the fields to give gson explicit names to work with. – laalto Feb 01 '22 at 21:34

0 Answers0