@SerializedName checking for valid Java field name ?

182 views
Skip to first unread message

doubled

unread,
Mar 16, 2009, 5:43:41 PM3/16/09
to google-gson
Trying out gson and it is working great for most part. Making my Java
code more strongly typed again :)

However one small issue is that the json string I'm trying to convert
to a POJO is containing the string "default". This is a reserved
keyword, so it is not possible to define for example: "private String
default;"

I taught the work around would be something like this:

@SerializedName("default")
private String _default;

However gson doesn't seem to allow that. It seems to check if the
provided name is a valid Java field name. Is there a reason for this
and is there any way around it???

I would have assumed that the main purpose of @SerializedName is to
provide the flexibility to map arbitrary json keys like
("default","int",...) to valid Java field names, but I guess I'm
missing something.

Thanks,

Peter

inder

unread,
May 5, 2009, 7:37:53 PM5/5/09
to google-gson
I agree: SerializedName should be smarter about this and entered a bug
in: http://code.google.com/p/google-gson/issues/detail?id=121
Thanks for the bug report
Inder
Reply all
Reply to author
Forward
0 new messages