當前位置: 首頁>>代碼示例>>Java>>正文


Java JSON.toJavaObject方法代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSON.toJavaObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSON.toJavaObject方法的具體用法?Java JSON.toJavaObject怎麽用?Java JSON.toJavaObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.fastjson.JSON的用法示例。


在下文中一共展示了JSON.toJavaObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_for_issue

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    Money money = new Money();
    money.currency = Currency.getInstance("CNY");
    money.amount = new BigDecimal("10.03");

    String json = JSON.toJSONString(money);

    Money moneyBack = JSON.parseObject(json, Money.class);
    Assert.assertEquals(money.currency, moneyBack.currency);
    Assert.assertEquals(money.amount, moneyBack.amount);

    JSONObject jsonObject = JSON.parseObject(json);
    Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
    Assert.assertEquals(money.currency, moneyCast.currency);
    Assert.assertEquals(money.amount, moneyCast.amount);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:Bug_for_issue_349.java

示例2: test_3

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void test_3() throws Exception {
    JSONObject map = new JSONObject();
    map.put("id", 1);
    map.put("name", "panlei");

    User user = JSON.toJavaObject(map, User.class);
    Assert.assertEquals(1L, user.getId());
    Assert.assertEquals("panlei", user.getName());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:TypeUtilsTest.java

示例3: testJson

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void testJson() throws Exception {
    Money money = new Money();
    money.currency = Currency.getInstance("CNY");
    money.amount = new BigDecimal("10.03");

    String json = JSON.toJSONString(money);
    System.out.println("json = " + json);

    Money moneyBack = JSON.parseObject(json, Money.class);
    System.out.println("money = " + moneyBack);

    JSONObject jsonObject = JSON.parseObject(json);
    Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
    System.out.printf("money = " + moneyCast);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:CurrencyTest3.java

示例4: test_for_issue

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    String json = "{\n" +
            " \"info\": {\n" +
            "        \"test\": \"\", \n" +
            "    }\n" +
            "}";

    JSONObject jsonObject = JSON.parseObject(json);
    TestModel loginResponse = JSON.toJavaObject(jsonObject, TestModel.class);

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:Issue1178.java

示例5: deserialze

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    JSONObject json = parser.parseObject();
    int num = json.getInteger("num");
    if (num == 1) {
        return (T) JSON.toJavaObject(json, B.class);
    } else if (num == 2) {
        return (T) JSON.toJavaObject(json, C.class);
    } else {
        return (T) JSON.toJavaObject(json, A.class);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:AbstractTest.java

示例6: test_for_issue

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    TestObject to = new TestObject();
    to.add("test1");
    to.add("test2");
    String text = JSON.toJSONString(to);
    System.out.println(text);
    JSONObject jo = JSON.parseObject(text);
    to = JSON.toJavaObject(jo, TestObject.class);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:Issue87_hashset.java

示例7: test_for_bug

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void test_for_bug() throws Exception {
    Entity entity = new Entity();
    entity.setHolder(new Holder<String>("AAA"));

    JSONObject json = (JSONObject) JSON.toJSON(entity);
    Entity entity2 = JSON.toJavaObject(json, Entity.class);
    Assert.assertEquals(JSON.toJSONString(entity), JSON.toJSONString(entity2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:Bug_101_for_rongganlin_case3.java

示例8: getJsonObj

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public static <T> T getJsonObj(Class<T> c, JSON content) {
    try {
        return JSON.toJavaObject(content, c);
    } catch (Exception e) {
        if (e != null) {
            Logger.d("fornia", "e.getMessage():" + e.getMessage());
        }
        return null;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:11,代碼來源:CommonParser.java

示例9: getJsonObj

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public static <T> T getJsonObj(Class<T> c, JSON content) {
    try {
        return JSON.toJavaObject(content, c);
    } catch (Exception e) {
        if (e != null) {
            LogInfo.log("fornia", "e.getMessage():" + e.getMessage());
        }
        return null;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:11,代碼來源:CommonParser.java

示例10: test_0

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public void test_0() throws Exception {
    A a = (A) JSON.toJavaObject(new JSONObject(), A.class);
    Assert.assertNotNull(a);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:5,代碼來源:JSON_toJavaObject_test.java

示例11: toObject

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public static <T> T toObject(Object jsonObject, Class<T> clz){
	if (Objects.isNull(jsonObject))
		return null;

	return JSON.toJavaObject((JSON)jsonObject, clz);
}
 
開發者ID:x7-framework,項目名稱:x7,代碼行數:7,代碼來源:JsonX.java

示例12: transferStringToSeed

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
public static Seed transferStringToSeed(String seed) {
    return JSON.toJavaObject(JSONObject.parseObject(seed), Seed.class);
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:4,代碼來源:VSCrawlerCommonUtil.java

示例13: doAliPayMobileReq

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
@Override
public Map doAliPayMobileReq(String jsonParam) {
    String logPrefix = "【支付寶APP支付下單】";
    BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
    Map<String, Object> bizParamMap = baseParam.getBizParamMap();
    if (ObjectValidUtil.isInvalid(bizParamMap)) {
        _log.warn("{}失敗, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
    }
    JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
    PayOrder payOrder = JSON.toJavaObject(payOrderObj, PayOrder.class);
    if (ObjectValidUtil.isInvalid(payOrder)) {
        _log.warn("{}失敗, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
    }
    String payOrderId = payOrder.getPayOrderId();
    String mchId = payOrder.getMchId();
    String channelId = payOrder.getChannelId();
    PayChannel payChannel = baseService4PayOrder.baseSelectPayChannel(mchId, channelId);
    alipayConfig.init(payChannel.getParam());
    AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
    AlipayTradeAppPayRequest alipay_request = new AlipayTradeAppPayRequest();
    // 封裝請求支付信息
    AlipayTradeAppPayModel model=new AlipayTradeAppPayModel();
    model.setOutTradeNo(payOrderId);
    model.setSubject(payOrder.getSubject());
    model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
    model.setBody(payOrder.getBody());
    model.setProductCode("QUICK_MSECURITY_PAY");
    alipay_request.setBizModel(model);
    // 設置異步通知地址
    alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
    // 設置同步地址
    alipay_request.setReturnUrl(alipayConfig.getReturn_url());
    String payParams = null;
    try {
        payParams = client.sdkExecute(alipay_request).getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    baseService4PayOrder.baseUpdateStatus4Ing(payOrderId, null);
    _log.info("{}生成請求支付寶數據,payParams={}", logPrefix, payParams);
    _log.info("###### 商戶統一下單處理完成 ######");
    Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
    map.put("payOrderId", payOrderId);
    map.put("payParams", payParams);
    return RpcUtil.createBizResult(baseParam, map);
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:49,代碼來源:PayChannel4AliServiceImpl.java

示例14: doAliTransReq

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
/**
 * 支付寶轉賬,文檔:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer
 * @param jsonParam
 * @return
 */
@Override
public Map doAliTransReq(String jsonParam) {
    String logPrefix = "【支付寶轉賬】";
    BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
    Map<String, Object> bizParamMap = baseParam.getBizParamMap();
    if (ObjectValidUtil.isInvalid(bizParamMap)) {
        _log.warn("{}失敗, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
    }
    JSONObject transOrderObj = baseParam.isNullValue("transOrder") ? null : JSONObject.parseObject(bizParamMap.get("transOrder").toString());
    TransOrder transOrder = JSON.toJavaObject(transOrderObj, TransOrder.class);
    if (ObjectValidUtil.isInvalid(transOrder)) {
        _log.warn("{}失敗, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
    }
    String transOrderId = transOrder.getTransOrderId();
    String mchId = transOrder.getMchId();
    String channelId = transOrder.getChannelId();
    PayChannel payChannel = baseService4TransOrder.baseSelectPayChannel(mchId, channelId);
    alipayConfig.init(payChannel.getParam());
    AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
    AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
    AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();
    model.setOutBizNo(transOrderId);
    model.setPayeeType("ALIPAY_LOGONID");                            // 收款方賬戶類型
    model.setPayeeAccount(transOrder.getChannelUser());              // 收款方賬戶
    model.setAmount(AmountUtil.convertCent2Dollar(transOrder.getAmount().toString()));
    model.setPayerShowName("支付轉賬");
    model.setPayeeRealName(transOrder.getUserName());
    model.setRemark(transOrder.getRemarkInfo());
    request.setBizModel(model);
    Map<String, Object> map = new HashMap<>();
    map.put("transOrderId", transOrderId);
    map.put("isSuccess", false);
    try {
        AlipayFundTransToaccountTransferResponse response = client.execute(request);
        if(response.isSuccess()) {
            map.put("isSuccess", true);
            map.put("channelOrderNo", response.getOrderId());
        }else {
            //出現業務錯誤
            _log.info("{}返回失敗", logPrefix);
            _log.info("sub_code:{},sub_msg:{}", response.getSubCode(), response.getSubMsg());
            map.put("channelErrCode", response.getSubCode());
            map.put("channelErrMsg", response.getSubMsg());
        }
    } catch (AlipayApiException e) {
        _log.error(e, "");
    }
    return RpcUtil.createBizResult(baseParam, map);
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:57,代碼來源:PayChannel4AliServiceImpl.java

示例15: getAliTransReq

import com.alibaba.fastjson.JSON; //導入方法依賴的package包/類
@Override
public Map getAliTransReq(String jsonParam) {
    String logPrefix = "【支付寶轉賬查詢】";
    BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
    Map<String, Object> bizParamMap = baseParam.getBizParamMap();
    if (ObjectValidUtil.isInvalid(bizParamMap)) {
        _log.warn("{}失敗, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
    }
    JSONObject transOrderObj = baseParam.isNullValue("transOrder") ? null : JSONObject.parseObject(bizParamMap.get("transOrder").toString());
    TransOrder transOrder = JSON.toJavaObject(transOrderObj, TransOrder.class);
    if (ObjectValidUtil.isInvalid(transOrder)) {
        _log.warn("{}失敗, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
    }
    String transOrderId = transOrder.getTransOrderId();
    String mchId = transOrder.getMchId();
    String channelId = transOrder.getChannelId();
    PayChannel payChannel = baseService4PayOrder.baseSelectPayChannel(mchId, channelId);
    alipayConfig.init(payChannel.getParam());
    AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
    AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest();
    AlipayFundTransOrderQueryModel model = new AlipayFundTransOrderQueryModel();
    model.setOutBizNo(transOrderId);
    model.setOrderId(transOrder.getChannelOrderNo());
    request.setBizModel(model);
    Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
    map.put("transOrderId", transOrderId);
    try {
        AlipayFundTransOrderQueryResponse response = client.execute(request);
        if(response.isSuccess()){
            map.putAll((Map) JSON.toJSON(response));
            map.put("isSuccess", true);
        }else {
            _log.info("{}返回失敗", logPrefix);
            _log.info("sub_code:{},sub_msg:{}", response.getSubCode(), response.getSubMsg());
            map.put("channelErrCode", response.getSubCode());
            map.put("channelErrMsg", response.getSubMsg());
        }
    } catch (AlipayApiException e) {
        _log.error(e, "");
    }
    return RpcUtil.createBizResult(baseParam, map);
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:45,代碼來源:PayChannel4AliServiceImpl.java


注:本文中的com.alibaba.fastjson.JSON.toJavaObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。