Description:
I believe the example code referenced in this issue contained a bug and that code was accidentally part of this PR which was recently merged.
If persistDefault is false, the new code will put() into preferences a reference to the same instance of defaultValue as what is put into preferenceDefaults.
I believe this would have the effect that if the user were to make any modifications to the value put in preferences those changes would get reflected in the stored default as well (which is obviously not what we want).
I believe the solution is to do what your set() method does: use GSON to create a copy, and put() that copy into preferences.
Steps To Reproduce:
I haven't actually tested it yet
Expected behavior:
Modifying the object stored in preferences should not also modify the object stored in preferenceDefaults
Description: I believe the example code referenced in this issue contained a bug and that code was accidentally part of this PR which was recently merged.
If persistDefault is false, the new code will put() into preferences a reference to the same instance of defaultValue as what is put into preferenceDefaults.
I believe this would have the effect that if the user were to make any modifications to the value put in preferences those changes would get reflected in the stored default as well (which is obviously not what we want).
I believe the solution is to do what your set() method does: use GSON to create a copy, and put() that copy into preferences.
Steps To Reproduce: I haven't actually tested it yet
Expected behavior: Modifying the object stored in
preferences
should not also modify the object stored inpreferenceDefaults