desaikush210 / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Gson serialized/deserialized issue when proguard enabled #609

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When proguard is enabled following json is generated (used gson.toJson(<class 
objectName>)
"{\"a\":\"google\",\"b\":\"19\",\"c\":\"Nexus 5\",\"d\":\"123459056012048\"}"

I am looking for 
"{\"architecture\":\"SGH-I747M\",\"os\":\"samsung\",\"osVersion\":\"16\",\"uniqu
eId\":\"123459056012048\"}"

Original issue reported on code.google.com by vi...@guusto.com on 13 Nov 2014 at 7:31

GoogleCodeExporter commented 9 years ago
you will have to keep the original classmembers for this model using custom 
proguard rules.

eg:

-keepclassmembers class com.example.device {
  public *;
}

if your class lookis like this 

package com.example;

public class Device {
  public String architecture;
  public String os;
  public String osVersion;
  public String uniqueId;
}

Original comment by remcomok...@gmail.com on 14 Nov 2014 at 1:18

GoogleCodeExporter commented 9 years ago
Thanks but I found solution. I added SerializedName

public class Device {
  @SerializedName("architecture")
public String architecture;

  @SerializedName("os")
  public String os;

  @SerializedName("osVersion")
  public String osVersion;

  @SerializedName("uniqueId")
  public String uniqueId;
}

Original comment by vi...@guusto.com on 14 Nov 2014 at 5:42