Gson serialization and deserialization not working as expected

To prevent model classes from obfuscation. I’ve added @SerializedName annotation. Here are my proguard rules.

-keepclassmembers class * { @com.google.gson.annotations.Expose <fields>; } -keepclasseswithmembers,allowobfuscation,includedescriptorclasses class * { @com.google.gson.annotations.Expose <fields>; }
                    <option>-dontnote com.google.gson.annotations.SerializedName</option>
                    <option>-keepclasseswithmembers,allowobfuscation,includedescriptorclasses
                        class * {
                        @com.google.gson.annotations.SerializedName
                        &lt;fields&gt;;
                        }
                    </option>
                    <option> -dontnote com.google.gson.**</option>
                    <option>-keepclassmembers,allowobfuscation,includedescriptorclasses class * extends com.google.gson.TypeAdapter {
                        public &lt;fields&gt;;
                        }</option>
                    <option>-keep,allowobfuscation,includedescriptorclasses class * implements com.google.gson.TypeAdapterFactory</option>
                    <option>-keep,allowobfuscation,includedescriptorclasses class * implements com.google.gson.JsonDeserializer</option>
                    <option>-keep,allowobfuscation,includedescriptorclasses class * implements com.google.gson.JsonSerializer</option>
                    <option>-keepclassmembers,allowobfuscation class * {
                        @com.google.gson.annotations.SerializedName &lt;fields&gt;;
                        }</option>

SerializedName annotation is not working as expected. Could you pls tell what is the mistake ?

In addition, I’ve ENUM classes in my project.

Hi,

Welcome to the ProGuard Community! I recommend to try and structure your keep rules like the one below. Make sure to use < and > characters directly to enclose fields instead of &lt; and &gt;.

-keepclassmembers,includedescriptorclasses class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

Also keep in mind when you use the alllowobfuscation option this keep rule will not prevent obfuscation it will just prevent shrinking and optimization. You may want to remove that option from your keep rules if you are trying to prevent obfuscation.

Best Regards,
Aissa