desaikush210 / google-gson

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

Serialization: Map<CustomEnum,XXX> -> @SerializedEnum is ignorred in enum's values #562

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
class Test{
   Map<OS,String> natives = new HashMap<OS,String>();
public Test(){
natives.put(OS.Windows,"1");
natives.put(OS.MacOSX,"1");
}
}

enum OS{
@SerializedName("windows")
Windows,
@SerializedName("unix")
Linux,
@SerializedName("osx")
MacOSX
}

Gson gson = new Gson();
gson.toJson(new Test());

What is the expected output? What do you see instead?
Expected:
{
natives{
"windows":"1",
"osx":"2"
}
}

Current:
{
natives{
"Windows":"1",
"MacOSX":"2"
}
}

What version of the product are you using? On what operating system?
Mac OS X 10.9
google-gson-2.2
java 1.6

Please provide any additional information below.

Original issue reported on code.google.com by yan.zait...@gmail.com on 24 Feb 2014 at 9:32

GoogleCodeExporter commented 9 years ago
@SerializedName is ignored only during serialization.

Now, i'am fixing it by ovveriding toString() in Enum class (OS.name() is 
ignored too)

Original comment by yan.zait...@gmail.com on 24 Feb 2014 at 9:34