List of usage examples for com.google.gson JsonObject toString
@Override
public String toString()
From source file:com.android.cloudfiles.cloudfilesforandroid.CloudFiles.java
License:Apache License
private String generateToken(String userName, String apiKey) throws IOException { JsonObject cred = new JsonObject(); cred.addProperty("username", userName); cred.addProperty("apiKey", apiKey); JsonObject rax = new JsonObject(); rax.add("RAX-KSKEY:apiKeyCredentials", cred); JsonObject obj = new JsonObject(); obj.add("auth", rax); String json = obj.toString(); RequestBody body = RequestBody.create(JSON, json); Request request = new Request.Builder().url(tokenURL).post(body).build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); return response.body().string(); }
From source file:com.android.tools.idea.editors.hierarchyview.HierarchyViewCaptureOptions.java
License:Apache License
public String serialize() { JsonObject obj = new JsonObject(); obj.addProperty(VERSION, myVersion); obj.addProperty(TITLE, myTitle);/*from ww w . j ava2 s. c o m*/ return obj.toString(); }
From source file:com.apifest.example.AddSenderIdInBodyAction.java
License:Apache License
@Override public HttpRequest execute(HttpRequest req, String internalURI, HttpResponse tokenValidationResponse) throws MappingException { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new String(req.getContent().toString(CharsetUtil.UTF_8))).getAsJsonObject(); log.info("request body: " + json); json.addProperty("senderId", "1232"); byte[] newContent = json.toString().getBytes(CharsetUtil.UTF_8); ChannelBuffer buf = ChannelBuffers.copiedBuffer(newContent); req.setContent(buf);/*from ww w . j a va 2 s . c om*/ HttpHeaders.setContentLength(req, newContent.length); return req; }
From source file:com.apifest.example.RemoveBalanceFilter.java
License:Apache License
@Override public HttpResponse execute(HttpResponse response) { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(response.getContent().toString(CharsetUtil.UTF_8)).getAsJsonObject(); log.info("response body: " + json.toString()); json.remove("balance"); log.info("modified response body: " + json.toString()); byte[] newContent = json.toString().getBytes(CharsetUtil.UTF_8); response.setContent(ChannelBuffers.copiedBuffer(newContent)); HttpHeaders.setContentLength(response, newContent.length); return response; }
From source file:com.apifest.oauth20.HttpRequestHandler.java
License:Apache License
protected HttpResponse handleAuthorize(HttpRequest req) { HttpResponse response = null;//from www . j ava 2 s . c o m try { String redirectURI = auth.issueAuthorizationCode(req); // TODO: validation http protocol? log.debug("redirectURI: {}", redirectURI); // return auth_code JsonObject obj = new JsonObject(); obj.addProperty("redirect_uri", redirectURI); response = Response.createOkResponse(obj.toString()); accessTokensLog.info("authCode {}", obj.toString()); } catch (OAuthException ex) { response = Response.createOAuthExceptionResponse(ex); invokeExceptionHandler(ex, req); } return response; }
From source file:com.apifest.oauth20.MongoDBManager.java
License:Apache License
@Override @SuppressWarnings("unchecked") public boolean storeScope(Scope scope) { boolean stored = false; String id = scope.getScope(); Gson gson = new Gson(); String json = gson.toJson(scope); JsonParser parser = new JsonParser(); JsonObject jsonObj = parser.parse(json).getAsJsonObject(); jsonObj.remove("scope"); // use scope name as _id jsonObj.addProperty(ID_NAME, id);/*from ww w.j av a 2s . c o m*/ try { // use ObjectMapper in order to represent expiresIn as integer not as double - 100 instead of 100.00 Map<String, Object> result = new ObjectMapper().readValue(jsonObj.toString(), Map.class); // if scope already exits, updates it, otherwise creates the scope BasicDBObject query = new BasicDBObject(ID_NAME, id); BasicDBObject newObject = new BasicDBObject(result); DBCollection coll = db.getCollection(SCOPE_COLLECTION_NAME); coll.update(query, newObject, true, false); stored = true; } catch (JsonParseException e) { log.error("cannot store scope {}", scope.getScope(), e); } catch (JsonMappingException e) { log.error("cannot store scope {}", scope.getScope(), e); } catch (IOException e) { log.error("cannot store scope {}", scope.getScope(), e); } return stored; }
From source file:com.apifest.oauth20.MongoDBManager.java
License:Apache License
protected String constructDbId(Object object) { Gson gson = new Gson(); String json = gson.toJson(object); JsonParser parser = new JsonParser(); JsonObject jsonObj = parser.parse(json).getAsJsonObject(); if (jsonObj.has("id")) { String id = jsonObj.get("id").getAsString(); jsonObj.remove("id"); jsonObj.addProperty(ID_NAME, id); }//from ww w .j a va2s. com return jsonObj.toString(); }
From source file:com.apifest.oauth20.persistence.mongodb.MongoDBManager.java
License:Apache License
@Override @SuppressWarnings("unchecked") public boolean storeScope(Scope scope) { boolean stored = false; String id = scope.getScope(); Gson gson = new Gson(); String json = gson.toJson(scope); JsonParser parser = new JsonParser(); JsonObject jsonObj = parser.parse(json).getAsJsonObject(); jsonObj.remove("scope"); // use scope name as _id jsonObj.addProperty(CLIENTS_ID, id); try {/*from w ww . ja v a2 s . c o m*/ // use ObjectMapper in order to represent expiresIn as integer not as double - 100 instead of 100.00 Map<String, Object> result = new ObjectMapper().readValue(jsonObj.toString(), Map.class); // if scope already exits, updates it, otherwise creates the scope BasicDBObject query = new BasicDBObject(CLIENTS_ID, id); BasicDBObject newObject = new BasicDBObject(result); DBCollection coll = db.getCollection(SCOPE_COLLECTION_NAME); coll.update(query, newObject, true, false); stored = true; } catch (JsonParseException e) { log.error("cannot store scope {}", scope.getScope(), e); } catch (JsonMappingException e) { log.error("cannot store scope {}", scope.getScope(), e); } catch (IOException e) { log.error("cannot store scope {}", scope.getScope(), e); } return stored; }
From source file:com.apifest.oauth20.persistence.mongodb.MongoDBManager.java
License:Apache License
protected String constructDbId(Object object) { Gson gson = new Gson(); String json = gson.toJson(object); JsonParser parser = new JsonParser(); JsonObject jsonObj = parser.parse(json).getAsJsonObject(); if (jsonObj.has("id")) { String id = jsonObj.get("id").getAsString(); jsonObj.remove("id"); jsonObj.addProperty(CLIENTS_ID, id); }/*from w w w .ja va 2 s.c om*/ return jsonObj.toString(); }
From source file:com.app.smarthome.SmartHomeApplication.java
private void Sdkinit() { JsonObject initJsonObjectIn = new JsonObject(); JsonObject initJsonObjectOut = new JsonObject(); String initOut;/* w w w . j a v a2 s . c o m*/ initJsonObjectIn.addProperty("typelicense", typelicense); initJsonObjectIn.addProperty("userlicense", userlicense); initJsonObjectIn.addProperty("filepath", filepath); String string = initJsonObjectIn.toString(); initOut = mBlNetwork.SDKInit(string); initJsonObjectOut = new JsonParser().parse(initOut).getAsJsonObject(); if (initJsonObjectOut.get("code").getAsInt() != 0) { Log.i("Sdkinit failed", initJsonObjectOut.get("msg").getAsString()); } // ?? HC_DVRManager.getInstance().initSDK(); }