Java Code Examples for com.jeesuite.common.json.JsonUtils#toJson()

The following examples show how to use com.jeesuite.common.json.JsonUtils#toJson() . 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: WxUserController.java    From oneplatform with Apache License 2.0 6 votes vote down vote up
/**
 * <pre>
 * 获取用户信息接口
 * </pre>
 */
@GetMapping("/info")
@ApiPermOptions(perms = PermissionType.Logined)
public String info(@PathVariable String appid, String sessionKey,
                   String signature, String rawData, String encryptedData, String iv) {
    final WxMaService wxService = weixinAppManager.getMaService(appid);

    // 用户信息校验
    if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
        return "user check failed";
    }

    // 解密用户信息
    WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);

    return JsonUtils.toJson(userInfo);
}
 
Example 2
Source File: WxUserController.java    From oneplatform with Apache License 2.0 6 votes vote down vote up
/**
 * <pre>
 * 获取用户绑定手机号信息
 * </pre>
 */
@GetMapping("/phone")
@ApiPermOptions(perms = PermissionType.Logined)
public String phone(@PathVariable String appid, String sessionKey, String signature,
                    String rawData, String encryptedData, String iv) {
    final WxMaService wxService = weixinAppManager.getMaService(appid);

    // 用户信息校验
    if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
        return "user check failed";
    }

    // 解密
    WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);

    return JsonUtils.toJson(phoneNoInfo);
}
 
Example 3
Source File: WebUtils.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public static  void responseOutJsonp(HttpServletResponse response,String callbackFunName,Object jsonObject) {  
    //将实体对象转换为JSON Object转换  
    response.setCharacterEncoding("UTF-8");  
    response.setContentType("text/plain; charset=utf-8");  
    PrintWriter out = null;  
    
    String json = (jsonObject instanceof String) ? jsonObject.toString() : JsonUtils.toJson(jsonObject);
    String content = callbackFunName + "("+json+")";
    try {  
        out = response.getWriter();  
        out.append(content);  
    } catch (IOException e) {  
        e.printStackTrace();  
    } finally {  
        if (out != null) {  
            out.close();  
        }  
    }  
}
 
Example 4
Source File: JsonMessageSerializer.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
/**
 * serialize
 *
 * @param topic topic associated with data
 * @param data  typed data
 * @return serialized bytes
 */
@Override
public byte[] serialize(String topic, Serializable data) {
    try {
        if (data == null)
            return null;
        else{     
        	String toString = isSimpleDataType(data) ? data.toString() : JsonUtils.toJson(data);
        	return  toString.getBytes(StandardCharsets.UTF_8.name());
        }
    } catch (UnsupportedEncodingException e) {
        throw new SerializationException("Error when serializing string to byte[] due to unsupported encoding UTF-8");
    }

}
 
Example 5
Source File: User.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	
	User user = new User();
	user.setId(100);
	user.setName("jack");
	
	DefaultMessage message = new DefaultMessage(user).consumerAckRequired(true).header("key1", "value1");
	String json = JsonUtils.toJson(message);
	System.out.println(json);
	
	message = JsonUtils.toObject(json,DefaultMessage.class);
	System.out.println(message);
}
 
Example 6
Source File: UploadTokenParam.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
public String getCallbackRuleAsJson(){
	if(StringUtils.isAnyBlank(callbackBody,callbackHost,callbackUrl))return null;
	Map<String, String> map = new HashMap<>(4);
	map.put("callbackBody", callbackBody);
	map.put("callbackHost", callbackHost);
	map.put("callbackUrl", callbackUrl);
	map.put("callbackBodyType", getCallbackBodyType());
	return JsonUtils.toJson(map);
}
 
Example 7
Source File: CacheHandler.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
/**
 * 生成查询缓存key
 * @param cacheInfo
 * @param param
 * @return
 */
@SuppressWarnings("unchecked")
private String genarateQueryCacheKey(String keyPattern,Object param){
	String text;
	try {
		Object[] args;
		if(param instanceof Map){
			Map<String, Object> map = (Map<String, Object>) param;
			if(map.containsKey(STR_PARAM + "1")){
				args = new String[map.size()/2];
				for (int i = 0; i < args.length; i++) {
					args[i] = CacheKeyUtils.objcetToString(map.get(STR_PARAM + (i+1)));
				}
			}else{
				args = new String[]{CacheKeyUtils.objcetToString(map)};
			}
		}else if(param instanceof BaseEntity){
			Serializable id = ((BaseEntity)param).getId();
			if(id != null && !"0".equals(id.toString())){	
				args = new String[]{(((BaseEntity)param).getId()).toString()};
			}else{
				args = new String[]{CacheKeyUtils.objcetToString(param)};
			}
		}else if(param instanceof Object[]){
			args = (Object[])param;
		}else if(param == null){
			args = new Object[0];
		}else{
			args = new String[]{CacheKeyUtils.objcetToString(param)};
		}
		
		text = StringUtils.join(args,"-");
	} catch (Exception e) {
		text = JsonUtils.toJson(param);
		e.printStackTrace();
	}
	if(text.length() > 64)text = DigestUtils.md5(text);

	return String.format(keyPattern, text);
}
 
Example 8
Source File: LoginSession.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
public String toJsonString(){
	return JsonUtils.toJson(this);
}
 
Example 9
Source File: ClearCommand.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public String serialize() {
	return JsonUtils.toJson(this);
}
 
Example 10
Source File: WrapperResponse.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return JsonUtils.toJson(this);
}