Otterman Otterman - 1 year ago 100
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{
private boolean showDonation;
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?


Answer Source

Try changing showDonation to show_Donation in the class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download