Java Code Examples for com.alibaba.fastjson.JSONObject#toJSON()

The following examples show how to use com.alibaba.fastjson.JSONObject#toJSON() . 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 check out the related API usage on the sidebar.
Example 1
/**
 * 读取数据字典
 *
 * @return
 */

@PostMapping("meta")
public Response meta() {
    MetaEntity metaEntity = MetaEntity.localEntity(getEntityName());
    JSONObject json = (JSONObject) JSONObject.toJSON(metaEntity);
    JSONObject properties = json.getJSONObject("properties");
    // 判断是否开启编号必填,如果是必填,需要修改编号校验必填
    SysOrgConfig config = sysOrgConfigService.getSysOrgConfig();
    if (BooleanUtils.isTrue(config.getIsNoRequired())) {
        JSONObject fdNo = properties.getJSONObject("fdNo");
        fdNo.put("notNull", true);
    }
    if (BooleanUtils.isTrue(config.getKeepGroupUnique())) {
        JSONObject fdName = properties.getJSONObject("fdName");
        fdName.put("unique", true);
    }
    return Response.ok(json);
}
 
Example 2
@GetMapping(value = "/list")
public Result<?> queryPageList(SysGatewayRoute sysGatewayRoute) {
	LambdaQueryWrapper<SysGatewayRoute> query = new LambdaQueryWrapper<>();
	query.eq(SysGatewayRoute::getStatus,1);
	List<SysGatewayRoute> ls = sysGatewayRouteService.list(query);
	JSONArray array = new JSONArray();
	for(SysGatewayRoute rt: ls){
		JSONObject obj = (JSONObject)JSONObject.toJSON(rt);
		if(oConvertUtils.isNotEmpty(rt.getPredicates())){
			obj.put("predicates", JSONArray.parseArray(rt.getPredicates()));
		}
		if(oConvertUtils.isNotEmpty(rt.getFilters())){
			obj.put("filters", JSONArray.parseArray(rt.getFilters()));
		}
		array.add(obj);
	}
	return Result.ok(array);
}
 
Example 3
/**
 * 发布新消息
 * @param dto
 * @param channel
 */
private void publishNewMessageEvent(MessageDTO dto, Channel channel) {
    // 判断是私聊还是群聊
    JSONObject message = (JSONObject)JSONObject.toJSON(dto);
    if(dto.getType() != null && !dto.getType().isEmpty()) {
        message.put("type", dto.getType());
    }
    if(channel.getType().equals("P")) {
        // 私聊
        message.put("userIds", dto.getSenderId().equals(channel.getFrom().getId()) ? channel.getTo().getId() : channel.getFrom().getId());
    } else {
        message.put("groupIds", channel.getId());
    }
    NotificationEvent event = new NewMessageEvent(message);
    event.trigger();
}
 
Example 4
/**
 * 这里可能不是特别合理,只为实现功能
 */
private Integer getOperationGroupId(Object[] args){
    Object arg = args[0];
    Integer operationGroupId = -1;
    if (arg instanceof JSONObject){
        operationGroupId = (Integer)((JSONObject)arg).get("groupId");
    }else{
        if (arg instanceof List) {
            JSONArray argArray = (JSONArray)JSONObject.toJSON(arg);
            JSONObject jsonObject = (JSONObject)argArray.get(0);
            operationGroupId = (Integer)jsonObject.get("groupId");
        }else {
            if (arg instanceof InstallationParam){
                InstallationParam installationParam = (InstallationParam)arg;
                Cluster cluster = installationParam.getCluster();
                operationGroupId = cluster.getGroupId();
            }else{
                JSONObject argJson = (JSONObject)JSONObject.toJSON(arg);
                operationGroupId = (Integer)argJson.get("groupId");
            }
        }
    }

    return operationGroupId;
}
 
Example 5
Source Project: xxpay-master   File: MchInfoController.java    License: MIT License 6 votes vote down vote up
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute MchInfo mchInfo, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = mchInfoService.count(mchInfo);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<MchInfo> mchInfoList = mchInfoService.getMchInfoList((pageIndex-1)*pageSize, pageSize, mchInfo);
    if(!CollectionUtils.isEmpty(mchInfoList)) {
        JSONArray array = new JSONArray();
        for(MchInfo mi : mchInfoList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(mi);
            object.put("createTime", DateUtil.date2Str(mi.getCreateTime()));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
Example 6
Source Project: xxpay-master   File: PayChannelController.java    License: MIT License 6 votes vote down vote up
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute PayChannel payChannel, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = payChannelService.count(payChannel);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<PayChannel> payChannelList = payChannelService.getPayChannelList((pageIndex-1)*pageSize, pageSize, payChannel);
    if(!CollectionUtils.isEmpty(payChannelList)) {
        JSONArray array = new JSONArray();
        for(PayChannel pc : payChannelList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(pc);
            object.put("createTime", DateUtil.date2Str(pc.getCreateTime()));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
Example 7
Source Project: xxpay-master   File: RefundOrderController.java    License: MIT License 6 votes vote down vote up
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute RefundOrder refundOrder, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = refundOrderService.count(refundOrder);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<RefundOrder> refundOrderList = refundOrderService.getRefundOrderList((pageIndex-1)*pageSize, pageSize, refundOrder);
    if(!CollectionUtils.isEmpty(refundOrderList)) {
        JSONArray array = new JSONArray();
        for(RefundOrder po : refundOrderList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(po);
            if(po.getCreateTime() != null) object.put("createTime", DateUtil.date2Str(po.getCreateTime()));
            if(po.getRefundAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(po.getRefundAmount()+""));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
Example 8
Source Project: xxpay-master   File: PayOrderController.java    License: MIT License 6 votes vote down vote up
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute PayOrder payOrder, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = payOrderService.count(payOrder);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<PayOrder> payOrderList = payOrderService.getPayOrderList((pageIndex-1)*pageSize, pageSize, payOrder);
    if(!CollectionUtils.isEmpty(payOrderList)) {
        JSONArray array = new JSONArray();
        for(PayOrder po : payOrderList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(po);
            if(po.getCreateTime() != null) object.put("createTime", DateUtil.date2Str(po.getCreateTime()));
            if(po.getAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(po.getAmount()+""));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
Example 9
Source Project: SpringBootLearn   File: TestController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 插入记录
 * @return
 */
@PostMapping("/insertModel")
public String insertModel() {
    EsModel esModel = new EsModel();
    esModel.setId(DateFormatUtils.format(new Date(),"yyyyMMddhhmmss"));
    esModel.setName("m-" + new Random(100).nextInt());
    esModel.setAge(30);
    esModel.setDate(new Date());
    JSONObject jsonObject = (JSONObject) JSONObject.toJSON(esModel);
    String id = ElasticsearchUtil.addData(jsonObject, indexName, esType, jsonObject.getString("id"));
    return id;
}
 
Example 10
Source Project: roncoo-pay   File: CnpPayService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 校验请求参数及支付配置
 * @param object
 * @param bindingResult
 * @param httpServletRequest
 * @return
 * @throws BizException
 */
public RpUserPayConfig checkParamAndGetUserPayConfig(Object object, BindingResult bindingResult, HttpServletRequest httpServletRequest)throws BizException{
    validator.validate(object, bindingResult);
    if (bindingResult.hasErrors()) {// 校验银行卡信息是否完整
        String errorResponse = getErrorResponse(bindingResult);
        LOG.info("请求参数异常:{}", errorResponse);
        throw new PayBizException(PayBizException.REQUEST_PARAM_ERR, errorResponse);
    }

    Object jsonObject = JSONObject.toJSON(object);

    Map<String, Object> jsonParamMap = JSONObject.parseObject(jsonObject.toString(), Map.class);
    LOG.info("parseObject:" + jsonParamMap);

    String payKey = String.valueOf(jsonParamMap.get("payKey"));

    RpUserPayConfig rpUserPayConfig = rpUserPayConfigService.getByPayKey(payKey);
    if (rpUserPayConfig == null) {
        LOG.info("payKey[{}]的商户不存在", payKey);
        throw new PayBizException(PayBizException.USER_PAY_CONFIG_IS_NOT_EXIST, "用户异常");
    }

    checkIp(rpUserPayConfig, httpServletRequest );// ip校验

    String sign = String.valueOf(jsonParamMap.get("sign"));
    if (!MerchantApiUtil.isRightSign(jsonParamMap, rpUserPayConfig.getPaySecret(), sign)) {
        LOG.info("参数[{}],MD5签名验证异常sign:{}", jsonParamMap, sign);
        throw new TradeBizException(TradeBizException.TRADE_ORDER_ERROR, "订单签名异常");
    }

    return rpUserPayConfig;
}
 
Example 11
Source Project: roncoo-pay   File: JsonUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 将Map内的参数,转换成Json实体,并写出
 * @param response
 * @param object
 * @throws IOException
 */
public static void responseJson(HttpServletResponse response,
                                Object object) throws IOException {


    Object toJSON = JSONObject.toJSON(object);
    try {
        response.getWriter().write(toJSON.toString());
    } catch (IOException e) {
        LOG.error(e);
    }
}
 
Example 12
Source Project: yue-library   File: AbstractRepository.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 插入数据-实体
 * 
 * @param paramIPO 参数IPO(POJO-IPO对象)
 * @param databaseFieldNamingStrategyEnum 数据库字段命名策略
 * @return 返回主键值
 */
public Long insert(Object paramIPO, FieldNamingStrategyEnum databaseFieldNamingStrategyEnum) {
	PropertyNamingStrategy propertyNamingStrategy = databaseFieldNamingStrategyEnum.getPropertyNamingStrategy();
	SerializeConfig serializeConfig = new SerializeConfig();
	serializeConfig.setPropertyNamingStrategy(propertyNamingStrategy);
	JSONObject paramJson = (JSONObject) JSONObject.toJSON(paramIPO, serializeConfig);
	return insert(paramJson);
}
 
Example 13
Source Project: code   File: FastJsonConvertUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <B>方法名称:</B>将对象转为JSONObject对象<BR>
 * <B>概要说明:</B>将对象转为JSONObject对象<BR>
 * @param obj 任意对象
 * @return JSONObject对象
 */
public static JSONObject convertObjectToJSONObject(Object obj){
	try {
		JSONObject jsonObject = (JSONObject) JSONObject.toJSON(obj);
		return jsonObject;
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}		
}
 
Example 14
Source Project: basic-tools   File: LogFormats.java    License: MIT License 5 votes vote down vote up
/**
 * 处理object 返回json对象
 */
private static JSONObject handleObjectJSON(Object target) {
    try {
        Object jsObj = JSONObject.toJSON(target);
        //数组json
        if (jsObj instanceof JSONArray) {
            ObjectBean objectBean = new ObjectBean(target);
            return handleObjectJSON(objectBean);
        }
        //对象json
        if (jsObj instanceof JSONObject) {
            JSONObject objCopy = (JSONObject) (jsObj);
            List<Field> objFields = getFieldListByClass(target.getClass());
            for (Field field : objFields) {
                field.setAccessible(true);
                Object fieldVal = field.get(target);
                hideProperties(objCopy, field, fieldVal);//敏感信息隐藏
            }
            return objCopy;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    //else
    return null;
}
 
Example 15
Source Project: sdmq   File: FastJsonConvert.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <B>方法名称:</B>将对象转为JSONObject对象<BR>
 * <B>概要说明:</B>将对象转为JSONObject对象<BR>
 *
 * @param obj 任意对象
 * @return JSONObject对象
 */
public static JSONObject convertObjectToJSONObject(Object obj) {
    try {
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(obj);
        return jsonObject;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 16
private void query(Map<String, NodeThreadPoolStatInfo> lastThread, List<QueryResult.Result> results) {
	Map<String,Map<String,Object>> mm = new HashMap<String, Map<String, Object>>();
	Map<String,Object> map = new HashMap<String, Object>();
	List<QueryResult.Series> series;
	List<String> columns;
	List<List<Object>> valus;
	if(CollectionUtils.isNotEmpty(results)){
           for (QueryResult.Result result : results) {
               series = result.getSeries();
               if(CollectionUtils.isNotEmpty(series)){
                   for (QueryResult.Series serie: series) {
                       columns=serie.getColumns();
                       valus = serie.getValues();
                       if(CollectionUtils.isNotEmpty(columns) && CollectionUtils.isNotEmpty(valus)){
                           for (List<Object> valu: valus) {
                               if(CollectionUtils.isNotEmpty(valu)){
                                   for (Integer i = 0;i<valu.size();i++){
                                       if(!columns.get(i).equals("time")){//过滤time字段
                                               map.put(columns.get(i),valu.get(i));
                                       }
                                   }
                                   mm.put((String) map.get("threadType"),map);
                               }
                           }
                       }
                   }
               }
           }
           if(mm.size() > 0){
               Iterator<Entry<String, Map<String, Object>>> mmIte = mm.entrySet().iterator();
               NodeThreadPoolStatInfo threadPoolStatInfo;
               while (mmIte.hasNext()) {
                   Entry<String, Map<String, Object>> re = mmIte.next();
                   JSON json = (JSON) JSONObject.toJSON(re.getValue());
                   threadPoolStatInfo = JSONObject.toJavaObject(json,NodeThreadPoolStatInfo.class);
                   lastThread.put(re.getKey(),threadPoolStatInfo);
               }
           }
       }
}
 
Example 17
private NodeJVMStatInfo getLastStatInfoFromDB(String host) {
	NodeJVMStatInfo statInfo = new NodeJVMStatInfo();
	try {
		String qstr = "select host,clusterName,oldMemUsed,oldMemMax,youngMemMax,youngMemUsed," +
				"oldCollectionCount,oldCollectionTime from jvm where host='"+host+"' and clusterName='"+clusterName+"'" +
				" order by time desc limit 1";
		QueryResult result = InflusDbUtil.query(qstr);
		Map<String,Object> map = new HashMap<String, Object>();
		if(result != null){
			List<QueryResult.Result> results = result.getResults();
			if(CollectionUtils.isNotEmpty(results)){
				for (QueryResult.Result res : results){
						List<String> columns = res.getSeries().get(0).getColumns();
						List<List<Object>> values = res.getSeries().get(0).getValues();
						if(CollectionUtils.isNotEmpty(values)){
							for (List<Object> value:values) {
								for (int i =0;i<value.size();i++){
									map.put(columns.get(i),value.get(i));
								}
							}
						}
				}
			}
		}
		if(map.size() > 0){
			JSON json = (JSON) JSONObject.toJSON(map);
			statInfo = JSONObject.toJavaObject(json,NodeJVMStatInfo.class);
		}
	} catch (Exception e) {
		LOGGER.error(host+":从数据库中获取上一条失败(jvm)!",e);
		return null;
	}
	return statInfo;
}
 
Example 18
Source Project: Jpom   File: BaseJsonModel.java    License: MIT License 4 votes vote down vote up
public JSONObject toJson() {
    return (JSONObject) JSONObject.toJSON(this);
}
 
Example 19
Source Project: jeecg-cloud   File: AutoLogAspect.java    License: Apache License 2.0 4 votes vote down vote up
private void saveSysLog(ProceedingJoinPoint joinPoint, long time) {
	MethodSignature signature = (MethodSignature) joinPoint.getSignature();
	Method method = signature.getMethod();

	SysLog sysLog = new SysLog();
	AutoLog syslog = method.getAnnotation(AutoLog.class);
	if(syslog != null){
		//注解上的描述,操作日志内容
		sysLog.setLogContent(syslog.value());
		sysLog.setLogType(syslog.logType());

	}

	//请求的方法名
	String className = joinPoint.getTarget().getClass().getName();
	String methodName = signature.getName();
	sysLog.setMethod(className + "." + methodName + "()");


	//设置操作类型
	if (sysLog.getLogType() == CommonConstant.LOG_TYPE_2) {
		sysLog.setOperateType(getOperateType(methodName, syslog.operateType()));
	}

	//获取request
	HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
	//请求的参数
	sysLog.setRequestParam(getReqestParams(request,joinPoint));

	//设置IP地址
	sysLog.setIp(IPUtils.getIpAddr(request));

	//获取登录用户信息
	LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
	if(sysUser!=null){
		sysLog.setUserid(sysUser.getUsername());
		sysLog.setUsername(sysUser.getRealname());

	}
	//耗时
	sysLog.setCostTime(time);
	sysLog.setCreateTime(new Date());
	//保存系统日志
	JSONObject jsonObject = (JSONObject) JSONObject.toJSON(sysLog);
	sysBaseRemoteApi.saveSysLog(jsonObject);
}
 
Example 20
Source Project: xxpay-master   File: JsonUtil.java    License: MIT License 4 votes vote down vote up
public static JSONObject getJSONObjectFromObj(Object object) {
    if (object == null) {
        return null;
    }
    return (JSONObject) JSONObject.toJSON(object);
}