List of usage examples for com.google.gson JsonElement toString
@Override
public String toString()
From source file:com.github.strawberry.util.Json.java
License:Open Source License
public static Map<String, Object> parse(String json) { JsonObject o = (JsonObject) parser.parse(json); Set<Map.Entry<String, JsonElement>> set = o.entrySet(); Map<String, Object> map = Maps.newHashMap(); for (Map.Entry<String, JsonElement> e : set) { String key = e.getKey();/*from w ww . j a v a2 s.c o m*/ JsonElement value = e.getValue(); if (!value.isJsonPrimitive()) { if (value.isJsonObject()) { map.put(key, parse(value.toString())); } else if (value.isJsonArray()) { map.put(key, parseArray(value.toString())); } } else { map.put(key, parsePrimitive(value)); } } return map; }
From source file:com.goodow.realtime.server.rpc.SaveHandler.java
License:Apache License
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String sid = requireParameter(req, Constants.Params.SESSION_ID); String key = requireParameter(req, Constants.Params.ID); JsonObject payload = new JsonParser().parse(RpcUtil.readRequestBody(req)).getAsJsonObject(); long version = payload.get(Params.REVISION).getAsLong(); String changes = payload.get(Params.CHANGES).toString(); ObjectId id = new ObjectId(key); Session session = new Session(context.get().getAccountInfo().getUserId(), sid); long resultingVersion; if (version == 0) { JsonArray jsonArray = new JsonParser().parse(changes).getAsJsonArray(); List<Delta<String>> deltas = new ArrayList<Delta<String>>(jsonArray.size()); for (JsonElement e : jsonArray) { deltas.add(new Delta<String>(session, e.toString())); }// w w w. j ava2s . c o m loader.create(id, deltas); resultingVersion = deltas.size(); } else { ServerMutateRequest mutateRequest = new ServerMutateRequest(); mutateRequest.setSession(new ObjectSession(id, session)); mutateRequest.setVersion(version); mutateRequest.setDeltas(changes); MutateResult res; try { res = slobFacilities.getSlobStore().mutateObject(mutateRequest); } catch (SlobNotFoundException e) { throw new BadRequestException("Object not found or access denied", e); } catch (AccessDeniedException e) { throw new BadRequestException("Object not found or access denied", e); } resultingVersion = res.getResultingVersion(); } JsonObject json = new JsonObject(); json.addProperty(Constants.Params.REVISION, resultingVersion); RpcUtil.writeJsonResult(req, resp, json.toString()); }
From source file:com.google.appinventor.components.runtime.ActivityProbeSensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, ACTIVITY_PROBE); Log.i(TAG, "Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.BatterySensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, BATTERYSENSOR_PROBE); Log.i(TAG, "Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.CallLogHistory.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering calllogs requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, CALLLOG_PROBE); if (afterDate != 0) ((JsonObject) dataRequest).addProperty("afterDate", afterDate); ((JsonObject) dataRequest).addProperty("hideSensitiveData", privacySafe); Log.i(TAG, "CallLog request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.CellTowerProbeSensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, CELLTOWER_PROBE); Log.i(TAG, "Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.LightSensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, LIGHTSENSOR_PROBE); Log.i(TAG, "Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.LocationProbeSensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering location data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, SIMPLE_LOCATION_PROBE); ((JsonObject) dataRequest).addProperty("goodEnoughAccurary", goodEnoughAccurary); ((JsonObject) dataRequest).addProperty("useGPS", useGPS); ((JsonObject) dataRequest).addProperty("useNetwork", useNetwork); ((JsonObject) dataRequest).addProperty("useCache", useCache); Log.i(TAG, "Location Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.PedometerSensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, PEDOMETER_PROBE); ((JsonObject) dataRequest).addProperty(PedometerKeys.SENSITIVITY_LEVEL, this.sensitivityLevel); Log.i(TAG, "Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }
From source file:com.google.appinventor.components.runtime.ProximitySensor.java
License:Open Source License
@Override public void registerDataRequest(int interval, int duration) { // TODO Auto-generated method stub Log.i(TAG, "Registering data requests."); JsonElement dataRequest = null; dataRequest = getDataRequest(interval, duration, PROXIMITYSENSOR_PROBE); Log.i(TAG, "Data request: " + dataRequest.toString()); mBoundFunfManager.requestData(listener, dataRequest); }