com.jdroid.javaweb.google.gcm.GcmResponseParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdroid-java-webapp Show documentation
Show all versions of jdroid-java-webapp Show documentation
Jdroid library for Java Web apps
The newest version!
package com.jdroid.javaweb.google.gcm;
import com.jdroid.java.http.parser.json.JsonParser;
import com.jdroid.java.json.JSONObject;
import java.util.List;
public class GcmResponseParser extends JsonParser {
@Override
public Object parse(JSONObject json) {
GcmResponse gcmResponse = new GcmResponse();
gcmResponse.setSuccess(json.optInt("success"));
gcmResponse.setFailure(json.optInt("failure"));
gcmResponse.setCanonicalIds(json.optInt("canonical_ids"));
gcmResponse.setMulticastId(json.optInt("multicast_id"));
List results = parseList(json, "results", new GcmResultParser());
gcmResponse.setResults(results);
return gcmResponse;
}
private class GcmResultParser extends JsonParser {
@Override
public Object parse(JSONObject json) {
GcmResult gcmResult = new GcmResult();
gcmResult.setMessageId(json.optString("message_id"));
gcmResult.setRegistrationId(json.optString("registration_id"));
gcmResult.setError(json.optString("error"));
return gcmResult;
}
}
}