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

The following examples show how to use com.alibaba.fastjson.JSON#toJSONString() . 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: LogAspectUtil.java    From spring-boot-api-project-seed with Apache License 2.0 6 votes vote down vote up
/**
 * 删除参数中的敏感内容
 * @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 2
Source File: FastJson37Issue.java    From actframework with 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 3
Source File: RoleController.java    From company_open with GNU General Public License v2.0 6 votes vote down vote up
@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 4
Source File: WXReflectionUtils.java    From weex with 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 5
Source File: HttpUtils.java    From we-cmdb with 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 6
Source File: MockOperDefineController.java    From dubbo-mock with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: SimpleClient4Shadow.java    From rpi with 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 8
Source File: Jsoner.java    From ICERest with 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 9
Source File: UserServiceImplement.java    From withme3.0 with 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 10
Source File: JSONUtils.java    From yyblog with 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 File: AccessInterceptor.java    From goods-seckill with 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 File: CameraJsonCollection.java    From FimiX8-RE with 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 File: FileSearch.java    From clouddisk with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return JSON.toJSONString(this, true);
}
 
Example 14
Source File: User.java    From springBoot-study with Apache License 2.0 4 votes vote down vote up
/** 
 * 
 */
@Override
public String toString() {
	return JSON.toJSONString(this);
}
 
Example 15
Source File: BeanUtilsTest.java    From yuzhouwan with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return JSON.toJSONString(this);
}
 
Example 16
Source File: UserController.java    From star-zone with 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 17
Source File: Jsoner.java    From ICERest with 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 18
Source File: ActivityEntity.java    From dtsopensource with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return JSON.toJSONString(this);
}
 
Example 19
Source File: JsonUtil.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
public static String toJson(Object o) {
    return JSON.toJSONString(o);
}
 
Example 20
Source File: Parameter.java    From ontology-java-sdk with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public String toString() {
    return JSON.toJSONString(this);
}