I have some pojo classes in my application and proguard was open before the update, now I added the keep class properties to the proguard rules for these models.. but I was saving the data as shared prefrences with json/gson.. now when I want to pull the data, the variable names come as a, b, c.. how can i fix this
public class WaterModel {
private int id;
private String date;
private int waterMl;
private float waterPercent;
}
Gson gson = new Gson();
String json = sharedPreferences.getString(WATER_LIST, null);
Log.d(TAG, "dailyWater " + json);
Type type = new TypeToken<List<WaterModel>>() {}.getType();
List<WaterModel> modelList = gson.fromJson(json, type);
result:
[{"a":1, "b":"20/07/2022", "c":750,"d":12.5}]
Room Database
for (int i = 0; i < modelList.size(); i++) {
DailyWater dailyWater = new DailyWater();
dailyWater.setDayId(daycurrent.getId());
dailyWater.setDate(formatDatev1(modelList.get(i).getDate()));
dailyWater.setWaterMl(modelList.get(i).getWaterMl());
dailyWater.setWaterPercent(modelList.get(i).getWaterPercent());
dailyWater.setTime(milliseconds(modelList.get(i).getDate()));
dailyWaterDao.insertDailyWater(dailyWater);
}
You have saved model class as string so unfortunately you can not do anything for already saved json string in shared preferenc however I would suggest to keep WaterModel class so next time when you will save you will get same variable name as in model class.
But you can't do anything for already saved string so try to override that json string in preference.
-keep class com.app.model.** { *; }