Otterman Otterman - 4 months ago 20
JSON Question

JSON to GSON Modeling

Given the following JSON:

{
"rmhc_config": {
"show_donation": true,
"campaignEnabled": true,
.
.
.


I have the following class model set up

public class RMHCConfigModel implements Serializable{
@SerializedName("show_donation")
private boolean showDonation;
@SerializedName("campaignEnabled")
private boolean campaignEnabled;
.
.
.


Accessed via:

Gson gson = new Gson();
RMHCConfigModel config = gson.fromJson(configValue.toString(), RMHCConfigModel.class);


I have verified configValue.toString() is returning the proper JSON in String format.

The problem is showDonation is being returned as false. I can't seem to figure out why. campaignEnabled is correctly returned, does this has anything to do with showDonation being the first element?

Thanks,
Otterman

Answer

Try changing showDonation to show_Donation in the class.

Comments