Java Code Examples for cn.hutool.json.JSONUtil#toJsonStr()
The following examples show how to use
cn.hutool.json.JSONUtil#toJsonStr() .
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: AliOssTemplate.java From magic-starter with GNU Lesser General Public License v3.0 | 5 votes |
/** * 获取上传凭证,普通上传 * TODO 上传大小限制、基础路径 * * @param bucketName 存储桶名称 * @param expireTime 过期时间,单位秒 * @return 上传凭证 */ public String getUploadToken(String bucketName, long expireTime) { String baseDir = "upload"; long expireEndTime = System.currentTimeMillis() + expireTime * 1000; Date expiration = new Date(expireEndTime); PolicyConditions policy = new PolicyConditions(); // 默认大小限制10M policy.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, ossProperties.getAliOss() .getArgs() .get("contentLengthRange", 1024 * 1024 * 10)); policy.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, baseDir); String postPolicy = ossClient.generatePostPolicy(expiration, policy); byte[] binaryData = postPolicy.getBytes(StandardCharsets.UTF_8); String encodedPolicy = BinaryUtil.toBase64String(binaryData); String postSignature = ossClient.calculatePostSignature(postPolicy); Map<String, String> respMap = new LinkedHashMap<>(16); respMap.put("accessid", ossProperties.getAliOss() .getAccessKey()); respMap.put("policy", encodedPolicy); respMap.put("signature", postSignature); respMap.put("dir", baseDir); respMap.put("host", getOssEndpoint(bucketName)); respMap.put("expire", String.valueOf(expireEndTime / 1000)); return JSONUtil.toJsonStr(respMap); }
Example 2
Source File: RedisUtils.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
/** * Object转成JSON数据 */ private String toJson(Object object){ if (object instanceof Integer || object instanceof Long || object instanceof Float || object instanceof Double || object instanceof Boolean || object instanceof String){ return String.valueOf(object); } return JSONUtil.toJsonStr(object); }
Example 3
Source File: MyHttpJsonMessageConverter.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
@Override public String toJson(Object obj) throws Exception { return JSONUtil.toJsonStr(obj); }
Example 4
Source File: MyHttpJsonMessageConverter.java From SubTitleSearcher with Apache License 2.0 | 4 votes |
@Override public String toJson(Object obj) throws Exception { return JSONUtil.toJsonStr(obj); }
Example 5
Source File: HwYunMsgSender.java From WePush with MIT License | 4 votes |
@Override public SendResult send(String[] msgData) { SendResult sendResult = new SendResult(); try { //APP接入地址+接口访问URI String url = App.config.getHwAccessUrl(); //APP_Key String appKey = App.config.getHwAppKey(); //APP_Secret String appSecret = App.config.getHwAppSecretPassword(); //国内短信签名通道号或国际/港澳台短信通道号 String sender = App.config.getHwSenderCode(); String signature = App.config.getHwSignature(); //模板ID String templateId = HwYunMsgMaker.templateId; //模板变量 String templateParas = JSONUtil.toJsonStr(hwYunMsgMaker.makeMsg(msgData)); String receiver = msgData[0]; if (PushControl.dryRun) { sendResult.setSuccess(true); return sendResult; } else { //请求Body,不携带签名名称时,signature请填null String body = buildRequestBody(sender, receiver, templateId, templateParas, "", signature); if (null == body || body.isEmpty()) { sendResult.setSuccess(false); sendResult.setInfo("body is null."); log.error("body is null."); return sendResult; } //请求Headers中的X-WSSE参数值 String wsseHeader = buildWsseHeader(appKey, appSecret); if (null == wsseHeader || wsseHeader.isEmpty()) { sendResult.setSuccess(false); sendResult.setInfo("wsse header is null."); log.error("wsse header is null."); return sendResult; } HttpResponse response = closeableHttpClient.execute(RequestBuilder.create("POST") .setUri(url) .addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded") .addHeader(HttpHeaders.AUTHORIZATION, AUTH_HEADER_VALUE) .addHeader("X-WSSE", wsseHeader) .setEntity(new StringEntity(body)).build()); // System.out.println(response.toString()); //打印响应头域信息 // System.out.println(EntityUtils.toString(response.getEntity())); //打印响应消息实体 // if (result.result == 0) { sendResult.setSuccess(true); // } else { // sendResult.setSuccess(false); // sendResult.setInfo(result.toString()); // } } } catch (Exception e) { sendResult.setSuccess(false); sendResult.setInfo(e.getMessage()); log.error(ExceptionUtils.getStackTrace(e)); } return sendResult; }