本文整理了Java中com.alibaba.fastjson.JSON.toJSON()
方法的一些代码示例,展示了JSON.toJSON()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.toJSON()
方法的具体详情如下:
包路径:com.alibaba.fastjson.JSON
类名称:JSON
方法名:toJSON
[英]This method serializes the specified object into its equivalent representation as a tree of JSONObjects.
[中]此方法将指定的对象序列化为JSONObject树的等效表示形式。
代码示例来源:origin: com.alibaba/fastjson
/**
* @deprecated
*/
public static Object toJSON(Object javaObject, ParserConfig parserConfig) {
return toJSON(javaObject, SerializeConfig.globalInstance);
}
代码示例来源:origin: com.alibaba/fastjson
Object key = entry.getKey();
String jsonKey = TypeUtils.castToString(key);
Object jsonValue = toJSON(entry.getValue(), config);
json.put(jsonKey, jsonValue);
Object jsonValue = toJSON(item, config);
array.add(jsonValue);
Object jsonValue = toJSON(item);
array.add(jsonValue);
Map<String, Object> values = javaBeanSerializer.getFieldValuesMap(javaObject);
for (Map.Entry<String, Object> entry : values.entrySet()) {
json.put(entry.getKey(), toJSON(entry.getValue()));
代码示例来源:origin: baomidou/mybatis-plus
Assertions.assertTrue(CollectionUtils.isNotEmpty(dataPage.getRecords()));
System.out.println(JSON.toJSONString(dataPage));
System.out.println(JSON.toJSON(dataPage.convert(CommonData::getId)));
Assertions.assertTrue(CollectionUtils.isNotEmpty(commonDataDataPage.getRecords()));
System.out.println(JSON.toJSONString(commonDataDataPage));
System.out.println(JSON.toJSON(commonDataDataPage.convert(CommonData::getId)));
代码示例来源:origin: com.alibaba/fastjson
/**
* This method serializes the specified object into its equivalent representation as a tree of
* {@link JSONObject}s.
*
*/
public static Object toJSON(Object javaObject) {
return toJSON(javaObject, SerializeConfig.globalInstance);
}
代码示例来源:origin: alibaba/fastjson
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
Class objClass = object.getClass();
Class[] interfaces = objClass.getInterfaces();
if (interfaces.length == 1 && interfaces[0].isAnnotation()) {
Class annotationClass = interfaces[0];
AnnotationType type = AnnotationType.getInstance(annotationClass);
Map<String, Method> members = type.members();
JSONObject json = new JSONObject(members.size());
Iterator<Map.Entry<String, Method>> iterator = members.entrySet().iterator();
Map.Entry<String, Method> entry;
Object val = null;
while (iterator.hasNext()) {
entry = iterator.next();
try {
val = entry.getValue().invoke(object);
} catch (IllegalAccessException e) {
// skip
} catch (InvocationTargetException e) {
// skip
}
json.put(entry.getKey(), JSON.toJSON(val));
}
serializer.write(json);
return;
}
}
}
代码示例来源:origin: com.alibaba/fastjson
public static JSONObject parseObject(String text) {
Object obj = parse(text);
if (obj instanceof JSONObject) {
return (JSONObject) obj;
}
try {
return (JSONObject) JSON.toJSON(obj);
} catch (RuntimeException e) {
throw new JSONException("can not cast to JSONObject.", e);
}
}
代码示例来源:origin: yaphone/itchat4j
public static String getSynckey(JSONObject obj) {
JSONArray obj2 = obj.getJSONArray("List");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < obj2.size(); i++) {
JSONObject obj3 = (JSONObject) JSON.toJSON(obj2.get(i));
sb.append(obj3.get("Val") + "|");
}
return sb.substring(0, sb.length() - 1); // 656159784|656159911|656159873|1491905341
}
代码示例来源:origin: jmdhappy/xxpay-master
@RequestMapping(value = "/mch_info/select")
public String selectMchInfo(@RequestParam String jsonParam) {
// TODO 参数校验
String param = new String(MyBase64.decode(jsonParam));
JSONObject paramObj = JSON.parseObject(param);
String mchId = paramObj.getString("mchId");
MchInfo mchInfo = mchInfoService.selectMchInfo(mchId);
JSONObject retObj = new JSONObject();
retObj.put("code", "0000");
if(StringUtils.isBlank(jsonParam)) {
retObj.put("code", "0001"); // 参数错误
retObj.put("msg", "缺少参数");
return retObj.toJSONString();
}
if(mchInfo == null) {
retObj.put("code", "0002");
retObj.put("msg", "数据对象不存在");
return retObj.toJSONString();
}
retObj.put("result", JSON.toJSON(mchInfo));
_log.info("result:{}", retObj.toJSONString());
return retObj.toJSONString();
}
代码示例来源:origin: com.alibaba/fastjson
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
Class objClass = object.getClass();
Class[] interfaces = objClass.getInterfaces();
if (interfaces.length == 1 && interfaces[0].isAnnotation()) {
Class annotationClass = interfaces[0];
AnnotationType type = AnnotationType.getInstance(annotationClass);
Map<String, Method> members = type.members();
JSONObject json = new JSONObject(members.size());
Iterator<Map.Entry<String, Method>> iterator = members.entrySet().iterator();
Map.Entry<String, Method> entry;
Object val = null;
while (iterator.hasNext()) {
entry = iterator.next();
try {
val = entry.getValue().invoke(object);
} catch (IllegalAccessException e) {
// skip
} catch (InvocationTargetException e) {
// skip
}
json.put(entry.getKey(), JSON.toJSON(val));
}
serializer.write(json);
return;
}
}
}
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
/**
* 判断是否是 ajax 请求
* 如果是,则返回 403 状态码
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
if (HttpUtils.isAjaxRequest((HttpServletRequest) request)) {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setStatus(HttpStatus.FORBIDDEN.value());
httpServletResponse.setContentType("application/json; charset=utf-8");
httpServletResponse.getWriter().print(JSON.toJSON(ResponseBo.error()));
return false;
} else {
saveRequestAndRedirectToLogin(request, response);
return false;
}
}
}
代码示例来源:origin: jmdhappy/xxpay-master
@RequestMapping(value = "/pay_channel/select")
public String selectPayChannel(@RequestParam String jsonParam) {
// TODO 参数校验
_log.info("selectPayChannel << {}", jsonParam);
JSONObject retObj = new JSONObject();
retObj.put("code", "0000");
if(StringUtils.isBlank(jsonParam)) {
retObj.put("code", "0001"); // 参数错误
retObj.put("msg", "缺少参数");
return retObj.toJSONString();
}
JSONObject paramObj = JSON.parseObject(new String(MyBase64.decode(jsonParam)));
String channelId = paramObj.getString("channelId");
String mchId = paramObj.getString("mchId");
PayChannel payChannel = payChannelService.selectPayChannel(channelId, mchId);
if(payChannel == null) {
retObj.put("code", "0002");
retObj.put("msg", "数据对象不存在");
return retObj.toJSONString();
}
retObj.put("result", JSON.toJSON(payChannel));
_log.info("selectPayChannel >> {}", retObj);
return retObj.toJSONString();
}
代码示例来源:origin: jmdhappy/xxpay-master
this.doNotify(payOrder);
retObj.put("result", JSON.toJSON(payOrder));
_log.info("selectPayOrder >> {}", retObj);
return retObj.toJSONString();
代码示例来源:origin: jmdhappy/xxpay-master
@RequestMapping("/view.html")
public String viewInput(String payOrderId, ModelMap model) {
PayOrder item = null;
if(StringUtils.isNotBlank(payOrderId)) {
item = payOrderService.selectPayOrder(payOrderId);
}
if(item == null) {
item = new PayOrder();
model.put("item", item);
return "pay_order/view";
}
JSONObject object = (JSONObject) JSON.toJSON(item);
if(item.getPaySuccTime() != null) object.put("paySuccTime", DateUtil.date2Str(new Date(item.getPaySuccTime())));
if(item.getLastNotifyTime() != null) object.put("lastNotifyTime", DateUtil.date2Str(new Date(item.getLastNotifyTime())));
if(item.getExpireTime() != null) object.put("expireTime", DateUtil.date2Str(new Date(item.getExpireTime())));
if(item.getAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(item.getAmount()+""));
model.put("item", object);
return "pay_order/view";
}
代码示例来源:origin: jmdhappy/xxpay-master
@RequestMapping("/view.html")
public String viewInput(String orderId, ModelMap model) {
MchNotify item = null;
if(StringUtils.isNotBlank(orderId)) {
item = mchNotifyService.selectMchNotify(orderId);
}
if(item == null) {
item = new MchNotify();
model.put("item", item);
return "mch_notify/view";
}
JSONObject object = (JSONObject) JSON.toJSON(item);
if(item.getCreateTime() != null) object.put("createTime", DateUtil.date2Str(item.getCreateTime()));
if(item.getUpdateTime() != null) object.put("updateTime", DateUtil.date2Str(item.getUpdateTime()));
if(item.getLastNotifyTime() != null) object.put("lastNotifyTime", DateUtil.date2Str(item.getLastNotifyTime()));
model.put("item", object);
return "mch_notify/view";
}
代码示例来源:origin: jmdhappy/xxpay-master
@RequestMapping("/view.html")
public String viewInput(String refundOrderId, ModelMap model) {
RefundOrder item = null;
if(StringUtils.isNotBlank(refundOrderId)) {
item = refundOrderService.selectRefundOrder(refundOrderId);
}
if(item == null) {
item = new RefundOrder();
model.put("item", item);
return "refund_order/view";
}
JSONObject object = (JSONObject) JSON.toJSON(item);
if(item.getRefundSuccTime() != null) object.put("refundSuccTime", DateUtil.date2Str(item.getRefundSuccTime()));
if(item.getExpireTime() != null) object.put("expireTime", DateUtil.date2Str(item.getExpireTime()));
if(item.getRefundAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(item.getRefundAmount()+""));
model.put("item", object);
return "refund_order/view";
}
代码示例来源:origin: jmdhappy/xxpay-master
@RequestMapping("/view.html")
public String viewInput(String transOrderId, ModelMap model) {
TransOrder item = null;
if(StringUtils.isNotBlank(transOrderId)) {
item = transOrderService.selectTransOrder(transOrderId);
}
if(item == null) {
item = new TransOrder();
model.put("item", item);
return "trans_order/view";
}
JSONObject object = (JSONObject) JSON.toJSON(item);
if(item.getTransSuccTime() != null) object.put("transSuccTime", DateUtil.date2Str(item.getTransSuccTime()));
if(item.getExpireTime() != null) object.put("expireTime", DateUtil.date2Str(item.getExpireTime()));
if(item.getAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(item.getAmount()+""));
model.put("item", object);
return "trans_order/view";
}
代码示例来源:origin: jmdhappy/xxpay-master
result = wxPayService.queryEntPay(transOrderId);
_log.info("{} >>> 成功", logPrefix);
map.putAll((Map) JSON.toJSON(result));
map.put("isSuccess", true);
map.put("transOrderId", transOrderId);
代码示例来源:origin: jmdhappy/xxpay-master
result = wxPayService.refundQuery(refundOrder.getChannelPayOrderNo(), refundOrder.getPayOrderId(), refundOrder.getRefundOrderId(), refundOrder.getChannelOrderNo());
_log.info("{} >>> 成功", logPrefix);
map.putAll((Map) JSON.toJSON(result));
map.put("isSuccess", true);
map.put("refundOrderId", refundOrderId);
代码示例来源:origin: jmdhappy/xxpay-master
AlipayTradeFastpayRefundQueryResponse response = client.execute(request);
if(response.isSuccess()){
map.putAll((Map) JSON.toJSON(response));
map.put("isSuccess", true);
}else {
代码示例来源:origin: jmdhappy/xxpay-master
AlipayFundTransOrderQueryResponse response = client.execute(request);
if(response.isSuccess()){
map.putAll((Map) JSON.toJSON(response));
map.put("isSuccess", true);
}else {
内容来源于网络,如有侵权,请联系作者删除!