Q:

Handling multiple attribute of same name via GSON

I am using Gson for maping from JSON in my android application. I have an issue where I have call e.g 
public class ABC {

    XYZ image;
}

This image Object is of XYZ class but the image object from server is a String object. I want Gson to ignore this XYZ image attribute but to map image in other attribute. like
public class ABC {

    @SerializedName("image")
    String imageUrl

    XYZ image;
}

It is possible to do this like above? Your help will be highly appreciated. Thanks 

A:

Annotate the fields you want to expose with @Expose and create your Gson instance with the builder, setting the appropriate configuration
public class ABC {    
    @Expose
    @SerializedName("image")
    String imageUrl

    XYZ image;
}
...
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

