Kamalone
Kamalone

Reputation: 4115

Saving object in SharedPreference as Json and Key Changes

I have my app in PlayStore. When I update my app with new exported apk SharedPreference Key is changing. You can understand it by seeing the json strings given below.

I am saving an object in shared preference as given below.

Please have a look on the jsons i am printing, the keys are changed to 'a','b' etc.

Upvotes: 0

Views: 216

Answers (2)

Kamalone
Kamalone

Reputation: 4115

It is my mistake.proguard was not enabled when I was exporting the APK.

Upvotes: 0

Alex Klimashevsky
Alex Klimashevsky

Reputation: 2495

It seams that you are using proguard and it obfuscates your User class.

Gson uses field names as keys by default. So I suggest to use @SerializedName annotation for correct json mapping

Upvotes: 1

Related Questions