List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:clientcommunicator.operations.SendChatRequest.java
@Override public void deserialize(String JSON) throws JSONException { JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject(); this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt()); this.content = obj.get("content").getAsString(); }
From source file:clientcommunicator.operations.YearOfPlentyRequest.java
@Override public void deserialize(String JSON) throws JSONException { JsonObject obj = new JsonParser().parse(JSON).getAsJsonObject(); this.playerIndex = new PlayerIdx(obj.get("playerIndex").getAsInt()); this.resource1 = ResourceType.valueOf(obj.get("resource1").getAsString().toUpperCase()); this.resource2 = ResourceType.valueOf(obj.get("resource2").getAsString().toUpperCase()); }
From source file:clientcommunicator.Server.Cookie.java
private JsonElement decodeJSON(String urlDecoded) throws MalformedCookieException { try {//from w ww. j a v a 2 s. c om urlDecoded = java.net.URLDecoder.decode(urlDecoded, "UTF-8"); return new JsonParser().parse(urlDecoded); } catch (UnsupportedEncodingException | JsonSyntaxException ex) { throw new MalformedCookieException(); } }
From source file:cloud.google.datastore.entity.commit.Commit.java
License:Apache License
private String getTransaction() { String result = ConnectionService .connect(GCDStatic.getDatastoreApiUrl() + config.getProjectName() + "/beginTransaction").body("") .accessToken(AuthenticationFactory.getInstance(config).getAccessToken()).post(); JsonElement jelement = new JsonParser().parse(result); JsonObject jobject = jelement.getAsJsonObject(); jelement = jobject.get("transaction"); return jelement != null ? jelement.getAsString() : ""; }
From source file:cloud.google.oauth2.MyWayAuthentication.java
License:Apache License
/** * Just return access token// w ww . ja va2 s. c om * */ @Override public String getAccessToken() { try { long iat = (System.currentTimeMillis() / 1000) - 60; long exp = iat + 3600; String urlParameters = "grant_type=" + GCDStatic.getGrant() + "&assertion=" + getAssertion(exp, iat); String result = ConnectionService.connect(GCDStatic.getAud()).body(urlParameters) .header("Content-Type", "application/x-www-form-urlencoded").post(); JsonElement jelement = new JsonParser().parse(result); JsonObject jobject = jelement.getAsJsonObject(); jelement = jobject.get("access_token"); return jelement != null ? jelement.getAsString() : ""; } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:cloudlens.cli.Whisk.java
License:Apache License
public static JsonObject main(JsonObject args) { final JsonObject res = new JsonObject(); try {/*from w w w.j a v a2s.c o m*/ final CL cl = new CL(System.out, System.err, false, true); String script = ""; String logURI = ""; if (args.has("script")) { script = args.getAsJsonPrimitive("script").getAsString(); } if (args.has("log")) { logURI = args.getAsJsonPrimitive("log").getAsString(); } try { final InputStream inputStream = FileReader.fetchFile(logURI); cl.source(inputStream); final List<ASTElement> top = ASTBuilder.parse(script); cl.launch(top); final JsonElement jelement = new JsonParser().parse(cl.cl.get("result").asString()); return jelement.getAsJsonObject(); } catch (final CLException e) { res.addProperty("error", e.getMessage()); System.err.println(e.getMessage()); } finally { cl.outWriter.flush(); cl.errWriter.flush(); } } catch (final Exception e) { res.addProperty("error", e.getMessage()); System.err.println(e.getMessage()); } return res; }
From source file:cloudlens.cli.Whisk.java
License:Apache License
public static void main(String[] args) { try {/*w w w . ja v a 2s . c o m*/ final FileInputStream inputStream = new FileInputStream(new File(args[0])); final BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream)); String line; final StringBuilder sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); final JsonElement jelement = new JsonParser().parse(sb.toString()); final JsonObject res = main(jelement.getAsJsonObject()); System.out.println(res); } catch (final FileNotFoundException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } }
From source file:cloudlens.parser.ASTBuilder.java
License:Apache License
public static List<ASTParagraph> parseZeppelinExport(String file) throws FileNotFoundException, IOException { final List<ASTParagraph> res = new ArrayList<>(); try (final FileReader rd = new FileReader(file);) { final JsonObject notebook = new JsonParser().parse(rd).getAsJsonObject(); final JsonArray paragraphs = notebook.getAsJsonArray("paragraphs"); final Iterator<JsonElement> it = paragraphs.iterator(); while (it.hasNext()) { final JsonObject p = it.next().getAsJsonObject(); final JsonPrimitive textOpt = p.getAsJsonPrimitive("text"); if (textOpt != null) { final String text = textOpt.getAsString(); if (text.startsWith("%cl")) { final String content = text.substring(3); final List<ASTElement> elements = parse(content); res.add(new ASTParagraph(elements)); } else { res.add(new ASTParagraph(text)); }/*from www . j a va 2s . c o m*/ } } } return res; }
From source file:club.jmint.crossing.client.CrossingClient.java
License:Apache License
public CallResult serviceCall(String inf, JsonObject params, boolean isEncrypt) { String result = null;// w ww. j a va2 s . c om CallResult cr = new CallResult(); try { if (isEncrypt) { result = call(inf, params.toString(), true); } else { result = call(inf, params.toString()); } } catch (CrossException e) { CrossLog.printStackTrace(e); CrossLog.logger.error("service call failed."); return null; } JsonParser jp = new JsonParser(); JsonObject jo; try { jo = (JsonObject) jp.parse(result); } catch (JsonSyntaxException e) { CrossLog.printStackTrace(e); CrossLog.logger.error("service call failed."); return null; } cr.errorCode = jo.getAsJsonPrimitive("errorCode").getAsInt(); if (cr.errorCode == ErrorCode.SUCCESS.getCode()) { cr.isSuccess = true; } else { cr.isSuccess = false; } cr.errorInfo = jo.getAsJsonPrimitive("errorInfo").getAsString(); if (jo.has("params")) { cr.data = jo.getAsJsonObject("params"); } return cr; }
From source file:club.jmint.crossing.specs.CrossingService.java
License:Apache License
protected JsonObject parseInputParams(String params, boolean encrypt) throws CrossException { //parsing//from ww w .ja v a 2 s. co m JsonParser jp = new JsonParser(); JsonObject jo, jode, joparams; try { jo = (JsonObject) jp.parse(params); } catch (JsonSyntaxException e) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(), ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo()); } String encrypted, jsonParams; if (encrypt) { if (!jo.has("encrypted")) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MISSING.getCode(), ErrorCode.COMMON_ERR_PARAM_MISSING.getInfo()); } encrypted = jo.getAsJsonPrimitive("encrypted").getAsString(); jsonParams = buildDecrypt(encrypted); if (jsonParams == null) { throw new CrossException(ErrorCode.COMMON_ERR_DECRYPTION.getCode(), ErrorCode.COMMON_ERR_DECRYPTION.getInfo()); } try { jode = (JsonObject) jp.parse(jsonParams); } catch (JsonSyntaxException e) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(), ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo()); } jo = jode; } //Check signature if (!jo.has("sign")) { throw new CrossException(ErrorCode.COMMON_ERR_SIGN_MISSING.getCode(), ErrorCode.COMMON_ERR_SIGN_MISSING.getInfo()); } String signValue = jo.getAsJsonPrimitive("sign").getAsString(); if (!jo.has("params")) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MISSING.getCode(), ErrorCode.COMMON_ERR_PARAM_MISSING.getInfo()); } String inputparams = jo.getAsJsonObject("params").toString(); String signCheck = buildSign(inputparams, signKey); if (!signCheck.equals(signValue)) { throw new CrossException(ErrorCode.COMMON_ERR_SIGN_BAD.getCode(), ErrorCode.COMMON_ERR_SIGN_BAD.getInfo()); } try { joparams = (JsonObject) jp.parse(inputparams); } catch (JsonSyntaxException e) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(), ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo()); } return joparams; }