Gson: Gson serialized/deserialized issue when proguard enabled

Created on 19 Mar 2015  路  2Comments  路  Source: google/gson

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 [email protected] on 13 Nov 2014 at 7:31

Most helpful comment

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 [email protected] on 14 Nov 2014 at 5:42

All 2 comments

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 [email protected] on 14 Nov 2014 at 1:18

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 [email protected] on 14 Nov 2014 at 5:42

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GoogleCodeExporter picture GoogleCodeExporter  路  25Comments

GoogleCodeExporter picture GoogleCodeExporter  路  31Comments

GoogleCodeExporter picture GoogleCodeExporter  路  14Comments

GoogleCodeExporter picture GoogleCodeExporter  路  20Comments

kramer picture kramer  路  26Comments