Java Code Examples for io.vertx.core.json.JsonObject#toString()
The following examples show how to use
io.vertx.core.json.JsonObject#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PayBizContent.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
@Override public String toString() { JsonObject json = new JsonObject(); json.put("out_trade_no", this.outTradeNo); json.put("total_amount", CommonUtils.getStringFromIntFen(Integer.parseInt(this.totalAmount))); json.put("subject", this.subject); json.put("product_code", "QUICK_WAP_PAY"); if (null != this.passbackParams) { try { json.put("passback_params", URLEncoder.encode(this.passbackParams, AlipayConstants.CHARSET_UTF8)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return json.toString(); }
Example 2
Source File: RefundBizContent.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
@Override public String toString() { JsonObject bizContentJson = new JsonObject(); if(CommonUtils.notEmptyString(this.outTradeNo)){ bizContentJson.put("out_trade_no", this.outTradeNo); } if(CommonUtils.notEmptyString(this.tradeNo)){ bizContentJson.put("trade_no", this.tradeNo); } bizContentJson.put("refund_amount", CommonUtils.getStringFromIntFen(this.refundAmount)); if(CommonUtils.notEmptyString(this.refundReason)){ bizContentJson.put("refund_reason", this.refundReason); } if(CommonUtils.notEmptyString(this.storeId)){ bizContentJson.put("store_id", this.storeId); } return bizContentJson.toString(); }
Example 3
Source File: TemplateMessage.java From AlipayWechatPlatform with GNU General Public License v3.0 | 6 votes |
@Override public String toString(){ JsonObject jsObj = new JsonObject(); jsObj.put("touser", openid); jsObj.put("template_id", templateId); jsObj.put("url", url); JsonObject data = new JsonObject(); if(dataMap != null){ for(String key : dataMap.fieldNames()){ JsonObject item = new JsonObject(); item.put("value", dataMap.getString(key)); item.put("color", color); data.put(key,item); } } jsObj.put("data", data); return jsObj.toString(); }
Example 4
Source File: Pac4jUser.java From vertx-pac4j with Apache License 2.0 | 6 votes |
@Override public void writeToBuffer(Buffer buff) { super.writeToBuffer(buff); // Now write the remainder of our stuff to the buffer; final JsonObject profilesAsJson = new JsonObject(); profiles.forEach((name, profile) -> { final JsonObject profileAsJson = (JsonObject) DefaultJsonConverter.getInstance().encodeObject(profile); profilesAsJson.put(name, profileAsJson); }); final String json = profilesAsJson.toString(); byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8); buff.appendInt(jsonBytes.length) .appendBytes(jsonBytes); }
Example 5
Source File: HelpFunc.java From df_data_service with Apache License 2.0 | 6 votes |
/** * Used to format Livy statement result to a list a fields and types for schema creation. Only support %table now * @param livyStatementResult * @return string of fields with type */ public static String livyTableResultToAvroFields(JsonObject livyStatementResult, String subject) { if (livyStatementResult.getJsonObject("output").containsKey("data")) { JsonObject dataJason = livyStatementResult.getJsonObject("output").getJsonObject("data"); if (livyStatementResult.getString("code").contains("%table")) { //livy magic word %table JsonObject output = dataJason.getJsonObject("application/vnd.livy.table.v1+json"); JsonArray header = output.getJsonArray("headers"); for (int i = 0; i < header.size(); i++) { header.getJsonObject(i).put("type", typeHive2Avro(header.getJsonObject(i).getString("type"))); } JsonObject schema = new JsonObject().put("type", "record").put("name", subject).put("fields", header); return schema.toString(); } } else { return ""; } return ""; }
Example 6
Source File: JacksonPayloadMarshaller.java From nubes with Apache License 2.0 | 5 votes |
@Override public String marshallUnexpectedError(Throwable error, boolean displayDetails) { JsonObject json = new JsonObject(); JsonObject jsonError = new JsonObject(); json.put(ERROR_KEY, jsonError); jsonError.put(ERROR_CODE_KEY, 500); if (displayDetails) { jsonError.put(ERROR_MESSAGE_KEY, StackTracePrinter.asLineString(new StringBuilder(), error)); } else { jsonError.put(ERROR_MESSAGE_KEY, "Internal Server Error"); } return json.toString(); }
Example 7
Source File: RbacSecurityContext.java From enmasse with Apache License 2.0 | 5 votes |
public static String rbacToRole(String path, String verb) { JsonObject object = new JsonObject(); object.put("type", "path"); object.put("path", path); object.put("verb", verb); return object.toString(); }
Example 8
Source File: RbacSecurityContext.java From enmasse with Apache License 2.0 | 5 votes |
public static String rbacToRole(String namespace, ResourceVerb verb, String resource, String resourceName, String apiGroup) { JsonObject object = new JsonObject(); object.put("type", "resource"); object.put("namespace", namespace); object.put("verb", verb); object.put("resource", resource); object.put("name", resourceName); object.put("apiGroup", apiGroup); return object.toString(); }
Example 9
Source File: RbacSecurityContext.java From enmasse with Apache License 2.0 | 5 votes |
public static String rbacToRole(String namespace, ResourceVerb verb, String resource, String apiGroup) { JsonObject object = new JsonObject(); object.put("type", "resource"); object.put("namespace", namespace); object.put("verb", verb); object.put("resource", resource); object.put("apiGroup", apiGroup); return object.toString(); }
Example 10
Source File: JsonManagementStore.java From hono with Eclipse Public License 2.0 | 5 votes |
static String encodeCredentialsHierarchical(final List<CommonCredential> credentials) { final JsonObject result = new JsonObject(); for (CommonCredential entry : credentials) { final JsonObject c = JsonObject.mapFrom(entry); final String type = c.getString(CredentialsConstants.FIELD_TYPE); final String authId = c.getString(CredentialsConstants.FIELD_AUTH_ID); final JsonObject target = lookupEntry(result, type, authId); copyFields(c, target); } return result.toString(); }
Example 11
Source File: JacksonPayloadMarshaller.java From nubes with Apache License 2.0 | 5 votes |
@Override public String marshallHttpStatus(int statusCode, String errorMessage) { JsonObject json = new JsonObject(); JsonObject jsonError = new JsonObject(); json.put(ERROR_KEY, jsonError); jsonError.put(ERROR_CODE_KEY, statusCode); jsonError.put(ERROR_MESSAGE_KEY, errorMessage); return json.toString(); }
Example 12
Source File: ResultFormat.java From VX-API-Gateway with MIT License | 5 votes |
/** * 格式化返回结果其中data为1,code为状态码枚举类 * * @param code * @return */ public static String formatAsOne(HTTPStatusCodeMsgEnum code) { JsonObject result = new JsonObject(); result.put("status", code.getCode()); result.put("msg", code.getMsg()); result.put("data", 1); return result.toString(); }
Example 13
Source File: ResultFormat.java From VX-API-Gateway with MIT License | 5 votes |
/** * 格式化返回结果其中data为0,code为状态码枚举类 * * @param code * @return */ public static String formatAsZero(HTTPStatusCodeMsgEnum code) { JsonObject result = new JsonObject(); result.put("status", code.getCode()); result.put("msg", code.getMsg()); result.put("data", 0); return result.toString(); }
Example 14
Source File: ResultFormat.java From VX-API-Gateway with MIT License | 5 votes |
/** * 格式化返回结果其中data为[],code为状态码枚举类 * * @param code * @return */ public static String formatAsNewArray(HTTPStatusCodeMsgEnum code) { JsonObject result = new JsonObject(); result.put("status", code.getCode()); result.put("msg", code.getMsg()); result.put("data", new JsonArray()); return result.toString(); }
Example 15
Source File: ResultFormat.java From VX-API-Gateway with MIT License | 5 votes |
/** * 格式化返回结果其中data为{},code为状态码枚举类 * * @param code * @return */ public static String formatAsNewJson(HTTPStatusCodeMsgEnum code) { JsonObject result = new JsonObject(); result.put("status", code.getCode()); result.put("msg", code.getMsg()); result.put("data", new JsonObject()); return result.toString(); }
Example 16
Source File: ResultFormat.java From VX-API-Gateway with MIT License | 5 votes |
/** * 格式化返回结果其中data为null,code为状态码枚举类 * * @param code * @return */ public static String formatAsNull(HTTPStatusCodeMsgEnum code) { JsonObject result = new JsonObject(); result.put("status", code.getCode()); result.put("msg", code.getMsg()); result.putNull("data"); return result.toString(); }
Example 17
Source File: VertxRestDispatcher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
/** * Consumer will treat the response body as json by default, so it's necessary to wrap response body as Json string * to avoid deserialization error. * * @param message response body * @return response body wrapped as Json string */ String wrapResponseBody(String message) { if (isValidJson(message)) { return message; } JsonObject jsonObject = new JsonObject(); jsonObject.put("message", message); return jsonObject.toString(); }
Example 18
Source File: WxMessageBuilder.java From AlipayWechatPlatform with GNU General Public License v3.0 | 5 votes |
public static String prepareCustomText(String openid,String content){ JsonObject jsObj = new JsonObject(); jsObj.put("touser", openid); jsObj.put("msgtype", MsgType.Text.name()); JsonObject textObj = new JsonObject(); textObj.put("content", content); jsObj.put("text", textObj); return jsObj.toString(); }
Example 19
Source File: TemplateMessage.java From AlipayWechatPlatform with GNU General Public License v3.0 | 5 votes |
/** * 重写toString方法; * 方法将模板消息的内容一层一层封装成json对象,然后将最后的json对象转换成json字符串; * * @return json字符串 * Create by quandong */ @Override public String toString(){ JsonObject jsObj = new JsonObject(); JsonObject template = new JsonObject(); JsonObject context = new JsonObject(); // 构造参数数据的json对象 if(dataMap != null){ // 遍历参数数据,将每个item封装成json对象然后放到context的json对象中 for(String key : dataMap.fieldNames()) { JsonObject item = new JsonObject(); // 用于存储一个item的json对象 item.put("value", dataMap.getString(key)); // 每个item的值 item.put("color", color); // item的颜色 context.put(key,item); // 将item添加到context的json对象中 } } context.put("url", url); // 添加跳转url context.put("head_color", headColor); // 添加标题颜色 context.put("action_name", "点击查看详情"); // 提示信息 // 将模版ID和内容添加到模板json对象中 template.put("template_id", templateId); template.put("context", context); // 添加发送用户和模版ID jsObj.put("to_user_id", openid); jsObj.put("template", template); return jsObj.toString(); // 将json对象转换为字符串并返回 }
Example 20
Source File: LoginChainHandler.java From slime with MIT License | 4 votes |
@Override public boolean handle(BridgeEvent event) throws EventBridgeChainException { boolean isHandle = Boolean.FALSE; if(BridgeEventType.SEND == event.type()) { Vertx vertx = VertxHolder.getVertx(); SockJSSocket sockJSSocket = event.socket(); Map<String, Object> rawMessage = event.getRawMessage().getMap(); String replyAddress = (String) rawMessage.get("replyAddress"); String address = (String) rawMessage.get("address"); if("vertx.basicauthmanager.login".equals(address)) { @SuppressWarnings("unchecked") Map<String, String> credential = (Map<String, String>) rawMessage.get("body"); String userId = credential.get("username"); //String password = credential.get("password"); if(userId == null || "".equals(userId)) { logger.warn("Connection rejected"); sockJSSocket.close(); throw new EventBridgeChainException(true, "No user attached"); } else { boolean exists = WebSocketSessionHolder.exists(userId); if(exists) { throw new EventBridgeChainException(true, "User already registered"); } sockJSSocket.headers().set(WebSocketSessionHolder.USER_KEY, userId); requestLogService.logWebSocketConnection(sockJSSocket); WebSocketSessionHolder.add(userId, sockJSSocket); System.out.println(vertx); System.out.println(vertx.eventBus()); System.out.println(userId); RedisSockjsClient.PUBLISH("topic/chat/user", new JsonObject() .put("userId", userId)); // publish there is a new user coming // vertx.eventBus().publish("topic/chat/user", // new JsonObject() // .put("userId", userId)); // get all online and send back to JsonObject json = new JsonObject() .put("type", "login") // optional .put("address", replyAddress) .put("body", new JsonObject() .put("result", true) .put("list", WebSocketSessionHolder.getUsers())); String data = json.toString(); sockJSSocket.write(Buffer.buffer(data)); isHandle = Boolean.TRUE; } } } return isHandle; }