Java Code Examples for com.alibaba.fastjson.JSON#toJSONString()

The following examples show how to use com.alibaba.fastjson.JSON#toJSONString() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: rpi   File: SimpleClient4Shadow.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据属性key-value 生成shadow json格式数据
 *
 * @param attributeMap
 * @return
 */
private static String genUpdateShadowMsg(Map<String, Object> attributeMap) {
    Set<String> attSet = attributeMap.keySet();
    Map<String, Object> attMap = new LinkedHashMap<String, Object>();
    for (String attKey : attSet) {
        attMap.put(attKey, attributeMap.get(attKey));
    }

    Map<String, Object> reportedMap = new LinkedHashMap<String, Object>();
    reportedMap.put("reported", attMap);

    Map<String, Object> shadowJsonMap = new LinkedHashMap<String, Object>();
    shadowJsonMap.put("method", "update");
    shadowJsonMap.put("state", reportedMap);

    //shadow version自增
    shadowVersion++;

    shadowJsonMap.put("version", shadowVersion);

    return JSON.toJSONString(shadowJsonMap);
}
 
Example 2
/**
 * 删除参数中的敏感内容
 * @param obj 参数对象
 * @return 去除敏感内容后的参数对象
 */
public static String deleteSensitiveContent(Object obj) {
    JSONObject jsonObject = new JSONObject();
    if (obj == null || obj instanceof Exception) {
        return jsonObject.toJSONString();
    }
    String param = JSON.toJSONString(obj);
    try {
        jsonObject = JSONObject.parseObject(param);
    }catch (Exception e) {
        return String.valueOf(obj);
    }
    List<String> sensitiveFieldList = getSensitiveFieldList();
    for (String sensitiveField : sensitiveFieldList) {
        if (jsonObject.containsKey(sensitiveField)) {
            jsonObject.put(sensitiveField, "******");
        }
    }
    return jsonObject.toJSONString();
}
 
Example 3
@ResponseBody
@RequestMapping(value = "/selectMockRuleScript")
public String selectMockRuleScript(HttpServletRequest arg0, Boolean selectFlag) throws Exception {
    String serviceId = arg0.getParameter("serviceId");
    String mockTestIds = arg0.getParameter("mockTestIds");
    String[] mocks = mockTestIds.split(",");
    Integer[] integers = new Integer[mocks.length];
    for (int i = 0; i < mocks.length; i++) {
        integers[i] = Integer.valueOf(mocks[i]);
    }
    MockGenericService service = dubboMockServer.buildMockGenericService(Integer.valueOf(serviceId), integers);
    Map<String, String> map = Maps.newConcurrentMap();
    Set<String> set = service.getRules().keySet();
    for (String key : set) {
        MethodRule rule = service.getRules().get(key);
        map.put(key, rule.getTemplate().getRaw());
    }
    return JSON.toJSONString(map);
}
 
Example 4
Source Project: we-cmdb   File: HttpUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String postWithJson(Map<String, Object> msgs, String url)
        throws ClientProtocolException, IOException {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {
        String jsonParam = JSON.toJSONString(msgs);

        HttpPost post = new HttpPost(url);
        post.setHeader("Content-Type", APPLICATION_JSON);
        post.setEntity(new StringEntity(jsonParam, CHARSET_UTF_8));
        CloseableHttpResponse response = httpClient.execute(post);

        return new String(EntityUtils.toString(response.getEntity()).getBytes("iso8859-1"),CHARSET_UTF_8);
    } finally {
        httpClient.close();
    }
}
 
Example 5
Source Project: weex   File: WXReflectionUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Object parseArgument(Type paramClazz, Object value){
  String originValue;
  if (value instanceof String) {
    originValue = (String) value;
  } else {
    originValue = JSON.toJSONString(value);
  }

  if (paramClazz == int.class) {
    return WXUtils.getInt(originValue);
  } else if (paramClazz == String.class) {
    return originValue;
  } else if (paramClazz == long.class) {
    return  WXUtils.getLong(originValue);
  } else if (paramClazz == double.class) {
    return WXUtils.getDouble(originValue);
  } else if (paramClazz == float.class) {
    return WXUtils.getFloat(originValue);
  } else if (ParameterizedType.class.isAssignableFrom(paramClazz.getClass())) {
    return JSON.parseObject(originValue, paramClazz);
  } else if (IWXObject.class.isAssignableFrom(paramClazz.getClass())) {
    return JSON.parseObject(originValue, paramClazz);
  } else {
    return JSON.parseObject(originValue, paramClazz);
  }
}
 
Example 6
@RequestMapping("/getRoleList")
public void getRoleList(Role role,HttpServletResponse response,int page,int rows) throws IOException{
	response.setCharacterEncoding("utf-8") ;
	Page<Role> roles = roleService.findByParams(role, page, rows) ;
	for(Role r: roles.getRows()){
		String function_id = r.getFunction_id() ;
		if(function_id != null){
			String function_name = "" ;
			String ids[] = function_id.split(",") ;
			for(String id :ids){
				String name = functionService.selectByPrimaryKey(Integer.parseInt(id)).getFunction_name() ;
				function_name += name+"," ;
				r.setAll_function_name(function_name) ;
			}
		}
	}
	
	
	String json = JSON.toJSONString(roles) ;
	response.getWriter().print(json) ;
}
 
Example 7
Source Project: actframework   File: FastJson37Issue.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    String fastJsonVersion = JSON.VERSION;
    System.out.println("fastjson version: " + fastJsonVersion);

    Map<String, Long> intOverflowMap = new HashMap<>();
    long intOverflow = Integer.MAX_VALUE;
    intOverflowMap.put("v", intOverflow + 1);
    String sIntOverflow = JSON.toJSONString(intOverflowMap);
    System.out.println("prepare to parse overflow int val: " + sIntOverflow);
    try {
        JSON.parseObject(sIntOverflow, IntegerVal.class);
    } catch (Exception e) {
        System.out.println("We captured the Exception: " + e.getMessage());
    }

    Map<String, Double> floatOverflowMap = new HashMap<>();
    double floatOverflow = Float.MAX_VALUE;
    floatOverflowMap.put("v", floatOverflow + floatOverflow);
    String sFloatOverflow = JSON.toJSONString(floatOverflowMap);
    System.out.println("prepare to parse overflow float val: " + sIntOverflow);
    FloatVal floatVal = JSON.parseObject(sFloatOverflow, FloatVal.class);
    System.out.println("We expect an exception raised, but found it parsed out an invalid value: " + floatVal);
}
 
Example 8
Source Project: withme3.0   File: UserServiceImplement.java    License: MIT License 5 votes vote down vote up
@Override
public Response getCurrentUser(String token) {
    try {
        AuthUser authUser = JwtUtils.parseJWT(token);
        return new Response(1, "获取当前用户成功", JSON.toJSONString(authUser));
    } catch (Exception e) {
        e.printStackTrace();
        return new Response(-1, "获取当前用户异常", null);
    }
}
 
Example 9
Source Project: ICERest   File: Jsoner.java    License: Apache License 2.0 5 votes vote down vote up
public static String toJSON(Object object, SerializeConfig config, SerializeFilter filter) {
    if (serializerFeatures != null) {
        return JSON.toJSONString(object, config, filter, serializerFeatures);
    } else {
        return JSON.toJSONString(object, config, filter);
    }
}
 
Example 10
Source Project: yyblog   File: JSONUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Bean对象转JSON
 * 
 * @param object
 * @return
 */
public static String beanToJson(Object object) {
    if (object != null) {
        return JSON.toJSONString(object);
    } else {
        return null;
    }
}
 
Example 11
Source Project: goods-seckill   File: AccessInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
private void render(HttpServletResponse response, CodeMsg sessionError) throws IOException {
    response.setContentType("application/json");
    ServletOutputStream outputStream = response.getOutputStream();
    String str = JSON.toJSONString(Result.error(sessionError));
    outputStream.write(str.getBytes("UTF-8"));
    outputStream.flush();
    outputStream.close();
}
 
Example 12
Source Project: FimiX8-RE   File: CameraJsonCollection.java    License: MIT License 5 votes vote down vote up
public X8BaseCamJsonData defaultSystem(JsonUiCallBackListener callBackListener) {
    String sendString = JSON.toJSONString(createBaseCmd(2, "on", "default_setting"));
    X8BaseCamJsonData baseCamJsonData = new X8BaseCamJsonData();
    baseCamJsonData.setAddToSendQueue(false);
    baseCamJsonData.setOutTime(1000);
    baseCamJsonData.setMsgId(2);
    baseCamJsonData.setCamKey("default_setting");
    baseCamJsonData.setPayLoad(sendString.getBytes());
    baseCamJsonData.setJsonUiCallBackListener(callBackListener);
    baseCamJsonData.packCmd();
    return baseCamJsonData;
}
 
Example 13
Source Project: Mycat2   File: JsonUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String toJson(Object o) {
    return JSON.toJSONString(o);
}
 
Example 14
Source Project: dtsopensource   File: ActivityEntity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return JSON.toJSONString(this);
}
 
Example 15
Source Project: ICERest   File: Jsoner.java    License: Apache License 2.0 4 votes vote down vote up
public static String toJSON(Object object, SerializeConfig config, SerializerFeature... features) {
    return JSON.toJSONString(object, config, features);
}
 
Example 16
Source Project: clouddisk   File: FileSearch.java    License: MIT License 4 votes vote down vote up
@Override
public String toString() {
	return JSON.toJSONString(this, true);
}
 
Example 17
Source Project: springBoot-study   File: User.java    License: Apache License 2.0 4 votes vote down vote up
/** 
 * 
 */
@Override
public String toString() {
	return JSON.toJSONString(this);
}
 
Example 18
Source Project: yuzhouwan   File: BeanUtilsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return JSON.toJSONString(this);
}
 
Example 19
Source Project: star-zone   File: UserController.java    License: Apache License 2.0 4 votes vote down vote up
@RequestMapping("getProfileDetail")
public String getUserProfileDetail(HttpServletRequest request) {
    String userIdStr = request.getHeader("userId");
    UserProfileDetail detail = userProfileService.getUserProfileDetail(Long.valueOf(userIdStr));
    return JSON.toJSONString(detail);
}
 
Example 20
@Override
public String toString() {
    return JSON.toJSONString(this);
}