Share Coding

Tutorials, Problems, Stuffs …

GSON with reserved word in the data

When using GSON, a object class should be passed to the Gson parser.
How about if there is a field named ‘default’ or other JAVA reserved word in the data?

public class LockerImageSet {

    private String default;

    private String mapImage, buildingImage, lockerImage, aroundImage;

}

The following code shows how to do that by an annotation.

public class LockerImageSet {

    @SerializedName("default")
    private String defaultImage;

    private String mapImage, buildingImage, lockerImage, aroundImage;

}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: