Java Code Examples for com.alibaba.fastjson.JSON#toJSON()
The following examples show how to use
com.alibaba.fastjson.JSON#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: DefaultJockeyImpl.java From TLint with Apache License 2.0 | 6 votes |
@Override public void send(String type, WebView toWebView, Object withPayload, JockeyCallback complete) { int messageId = messageCount; if (complete != null) { add(messageId, complete); } if (withPayload != null) { withPayload = JSON.toJSON(withPayload); } String url = String.format("javascript:Jockey.trigger(\"%s\", %d, %s)", type, messageId, withPayload); toWebView.loadUrl(url); ++messageCount; }
Example 2
Source File: TSDBClient.java From aliyun-tsdb-java-sdk with Apache License 2.0 | 6 votes |
@Override public List<LastDataValue> queryLast(Collection<Timeline> timelines) throws HttpUnknowStatusException { Object timelinesJSON = JSON.toJSON(timelines); JSONObject obj = new JSONObject(); obj.put("queries", timelinesJSON); String jsonString = obj.toJSONString(); HttpResponse httpResponse = httpclient.post(HttpAPI.QUERY_LAST, jsonString); ResultResponse resultResponse = ResultResponse.simplify(httpResponse, this.httpCompress); HttpStatus httpStatus = resultResponse.getHttpStatus(); switch (httpStatus) { case ServerSuccessNoContent: return null; case ServerSuccess: String content = resultResponse.getContent(); List<LastDataValue> queryResultList = JSON.parseArray(content, LastDataValue.class); return queryResultList; case ServerNotSupport: throw new HttpServerNotSupportException(resultResponse); case ServerError: throw new HttpServerErrorException(resultResponse); case ServerUnauthorized: throw new HttpServerUnauthorizedException(resultResponse); default: throw new HttpUnknowStatusException(resultResponse); } }
Example 3
Source File: UserController.java From app-engine with Apache License 2.0 | 6 votes |
@BaseInfo(desc = "登陆", needAuth = AuthType.OPTION) @RequestMapping(value = "/login", method = RequestMethod.POST) @ApiOperation(value = "测试接口1", notes = "简单接口描述 userName必填", code = 200, produces = "application/json") public JSONObject login( HttpServletResponse response, @RequestParam String username, @RequestParam String password, @RequestParam(required = false, defaultValue = "false") boolean cookie ) { User user = userService.login(username, password); JSONObject result = (JSONObject) JSON.toJSON(user); if (cookie) { String cookieValue = CookieAuthSpi.generateCookie(user.getUid()); Cookie authCookie = new Cookie(CookieAuthSpi.COOKIE_NAME, cookieValue); authCookie.setMaxAge((int) TimeUnit.DAYS.toSeconds(1)); response.addCookie(authCookie); result.put("cookie", cookieValue); } else { result.put("mauth", MAuthSpi.generateMauth(user.getUid())); } return result; }
Example 4
Source File: MchNotifyController.java From xxpay-master with MIT License | 6 votes |
@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"; }
Example 5
Source File: PayOrderController.java From xxpay-master with MIT License | 6 votes |
@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"; }
Example 6
Source File: CommonTools.java From xiaoV with GNU General Public License v3.0 | 5 votes |
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 }
Example 7
Source File: MarketController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequestMapping("symbol-thumb-trend") public JSONArray findSymbolThumbWithTrend(){ List<ExchangeCoin> coins = coinService.findAllEnabled(); //List<CoinThumb> thumbs = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); //将秒、微秒字段置为0 calendar.set(Calendar.SECOND,0); calendar.set(Calendar.MILLISECOND,0); calendar.set(Calendar.MINUTE,0); long nowTime = calendar.getTimeInMillis(); calendar.add(Calendar.HOUR_OF_DAY,-24); JSONArray array = new JSONArray(); long firstTimeOfToday = calendar.getTimeInMillis(); for(ExchangeCoin coin:coins){ CoinProcessor processor = coinProcessorFactory.getProcessor(coin.getSymbol()); CoinThumb thumb = processor.getThumb(); JSONObject json = (JSONObject) JSON.toJSON(thumb); json.put("zone",coin.getZone()); List<KLine> lines = marketService.findAllKLine(thumb.getSymbol(),firstTimeOfToday,nowTime,"1hour"); JSONArray trend = new JSONArray(); for(KLine line:lines){ trend.add(line.getClosePrice()); } json.put("trend",trend); array.add(json); } return array; }
Example 8
Source File: TreeGrid.java From jeecg with Apache License 2.0 | 5 votes |
private String assembleFieldsJson() { String fieldsJson = ", 'fieldMap':" + JSON.toJSON(fieldMap); if (fieldMap != null && fieldMap.size() > 0) { Map<String, Object> resultMap = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : fieldMap.entrySet()) { resultMap.put("fieldMap." + entry.getKey(), entry.getValue()); } fieldsJson += ", " + JSON.toJSON(resultMap).toString().replace("{", "").replace("}", ""); } return fieldsJson; }
Example 9
Source File: SeriesGeneratorTest.java From rebuild with GNU General Public License v3.0 | 5 votes |
@Test public void testGenerate() throws Exception { Map<String, String> config = new HashMap<>(); config.put("seriesFormat", "Y-{YYYYMMDD}-{0000}"); config.put("seriesZero", "M"); SeriesGenerator generator = new SeriesGenerator(getSeriesField(), (JSONObject) JSON.toJSON(config)); System.out.println(generator.generate()); System.out.println(generator.generate()); System.out.println(generator.generate()); }
Example 10
Source File: PubServiceImpl.java From SuperBoot with MIT License | 5 votes |
@Override public BaseResponse register(RegisterUser registerUser) { if (!isAes()) { //执行数据解密 registerUser.setPlatform(aesDecrypt(registerUser.getPlatform())); registerUser.setVersion(aesDecrypt(registerUser.getVersion())); registerUser.setUserCode(aesDecrypt(registerUser.getUserCode())); registerUser.setUserPassword(aesDecrypt(registerUser.getUserPassword())); registerUser.setUserEmail(aesDecrypt(registerUser.getUserEmail())); registerUser.setUserPhone(aesDecrypt(registerUser.getUserPhone())); registerUser.setUserName(aesDecrypt(registerUser.getUserName())); registerUser.setEndTime(aesDecrypt(registerUser.getEndTime())); } BaseResponse response = userRemote.addUser(registerUser); if (BaseStatus.OK.getCode() == response.getStatus()) { //判断数据状态 if (StatusCode.ADD_SUCCESS.getCode() == response.getCode()) { JSONObject data = (JSONObject) JSON.toJSON(response.getData()); BaseToken bt = JSON.toJavaObject(data, BaseToken.class); //判断白名单,用户是否已经生成过TOKEN了,如果生成过则不再进行登陆操作 String token = getRedisUtils().getTokenAllow(bt.getUserId(), registerUser.getPlatform(), registerUser.getVersion()); if (null == token) { //生成新的TOKEN token = jwtUtils.generateToken(bt); //登陆后将TOKEN信息放入缓存 getRedisUtils().setTokenInfo(token, bt); getRedisUtils().setTokenAllow(bt.getUserId(), registerUser.getPlatform(), registerUser.getVersion(), token); } return new BaseResponse(StatusCode.ADD_SUCCESS, genResToken(bt, token)); } } return response; }
Example 11
Source File: LogAspect.java From DimpleBlog with Apache License 2.0 | 5 votes |
/** * concat params * * @param paramsArray data * @return params data */ private String argsArrayToString(Object[] paramsArray) { StringBuilder params = new StringBuilder(); if (paramsArray != null && paramsArray.length > 0) { for (int i = 0; i < paramsArray.length; i++) { if (!isFilterObject(paramsArray[i])) { Object jsonObj = JSON.toJSON(paramsArray[i]); params.append(jsonObj.toString() + " "); } } } return params.toString().trim(); }
Example 12
Source File: JSONUtils.java From rebuild with GNU General Public License v3.0 | 5 votes |
/** * @param keys * @param values * @return */ public static JSONObject toJSONObject(String[] keys, Object[] values) { Assert.isTrue(keys.length <= values.length, "K/V 长度不匹配"); Map<String, Object> map = new HashMap<>(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return (JSONObject) JSON.toJSON(map); }
Example 13
Source File: JSONUtils.java From rebuild with GNU General Public License v3.0 | 5 votes |
/** * @param keys * @param valuesArray * @return */ public static JSONArray toJSONObjectArray(String[] keys, Object[][] valuesArray) { List<Map<String, Object>> array = new ArrayList<>(); for (Object[] o : valuesArray) { Map<String, Object> map = new HashMap<>(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], o[i]); } array.add(map); } return (JSONArray) JSON.toJSON(array); }
Example 14
Source File: PreferentialController.java From java_server with MIT License | 5 votes |
/** * 获取满减优惠信息(客户端分页) * @param campusId * @return */ @RequestMapping("getAllPref") @ResponseBody public JSONArray getAllPref(Integer campusId){ Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("campusId", campusId); List<Preferential> list = preferentialService.getPreferential(paramMap); return (JSONArray) JSON.toJSON(list); }
Example 15
Source File: ObjectUtil.java From joyqueue with Apache License 2.0 | 4 votes |
public static Map<String, Object> flatMap(Object obj) { Preconditions.checkArgument(obj != null, "invalid arg."); Map<String, Object> map = (JSONObject) JSON.toJSON(obj); return flatMap(map); }
Example 16
Source File: FastJSONAdaptor.java From elasticsearch-jdbc with MIT License | 4 votes |
@Override public JSONObject toJSONObject(Object obj) { return new FastJSONObject((com.alibaba.fastjson.JSONObject) JSON.toJSON(obj)); }
Example 17
Source File: JsonX.java From x7 with Apache License 2.0 | 4 votes |
public static Map<String,Object> toMap(Object obj){ return (Map<String,Object>) JSON.toJSON(obj); }
Example 18
Source File: MongoBean.java From MongoDB-Plugin with Apache License 2.0 | 4 votes |
public JSONObject toJSONObject() { return (JSONObject) JSON.toJSON(this); }
Example 19
Source File: CloneUtil.java From xian with Apache License 2.0 | 3 votes |
/** * clone a java bean. (We use fastjson.) * * @param from the bean you want to clone from. This must be a standard bean object. * @param beanClass the bean type * @param <T> the generic type. * @return the cloned object. */ public static <T> T cloneBean(T from, Class<T> beanClass) { if (from == null || from instanceof Collection || from.getClass().isArray()) { throw new IllegalArgumentException("Only java bean class is allowed here."); } JSONObject jsonObject = (JSONObject) JSON.toJSON(from); return jsonObject.toJavaObject(beanClass); }
Example 20
Source File: JsonView.java From ymate-platform-v2 with Apache License 2.0 | 2 votes |
/** * 构造器 * * @param obj Java对象 */ public JsonView(Object obj) { __jsonObj = JSON.toJSON(obj); }