Java Code Examples for com.alibaba.fastjson.JSON.parseObject()

The following are Jave code examples for showing how to use parseObject() of the com.alibaba.fastjson.JSON class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: probe   File: ProbeLuncher.java   Source Code and License Vote up 7 votes
/**
 * 解析参数
 *
 * @param args
 * @return
 * @throws FileNotFoundException
 */
private static Config parseConfig(String[] args) throws FileNotFoundException {
    Config config = Config.of();
    if (null != args && args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            if (args[i].startsWith("--config=")) {
                String[] conf = args[i].split("=");
                String content = new Scanner(new File(conf[1])).useDelimiter("\\Z").next();
                log.info("Probe config: \n{}", content);
                config = JSON.parseObject(content, Config.class);
                break;
            }
        }
    }
    return config;
}
 
Example 2
Project: GitHub   File: ConcurrentHashMapTest.java   Source Code and License Vote up 6 votes
public void test_concurrentHashmap() throws Exception {
    OffsetSerializeWrapper wrapper = new OffsetSerializeWrapper();
    wrapper.getOffsetTable().put(new MessageQueue(), new AtomicLong(123));
    String text = JSON.toJSONString(wrapper);
    Assert.assertEquals("{\"offsetTable\":{{\"items\":[]}:123}}", text);
    
    OffsetSerializeWrapper wrapper2 = JSON.parseObject(text, OffsetSerializeWrapper.class);
    Assert.assertEquals(1, wrapper2.getOffsetTable().size());
    
    Iterator<Map.Entry<MessageQueue, AtomicLong>> iter = wrapper2.getOffsetTable().entrySet().iterator();
    Map.Entry<MessageQueue, AtomicLong> entry = iter.next();
    Assert.assertEquals(0, entry.getKey().getItems().size());
    Assert.assertEquals(123L, entry.getValue().longValue());
}
 
Example 3
Project: GitHub   File: JSONScannerTest_scanFieldFloat.java   Source Code and License Vote up 5 votes
public void test_error_9() throws Exception {
    JSONException error = null;
    try {
        String text = "{\"value\":3.2},";
        JSON.parseObject(text, VO.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 4
Project: utilsLibrary   File: FastJsonUtils.java   Source Code and License Vote up 5 votes
/**
 * fastJson 解析Class
 *
 * @param json
 * @param cls
 * @param <T>
 * @return
 */
public static <T> T getObject(String json, Class<T> cls) {
    T t = null;
    try {
        t = JSON.parseObject(json, cls);
    } catch (Exception e) {
        e.printStackTrace();

    }
    return t;
}
 
Example 5
Project: GitHub   File: Issue1487.java   Source Code and License Vote up 5 votes
public void test_for_issue() throws Exception {
    Model model = new Model();
    model._id = 1001L;
    model.id = 1002L;

    String json = JSON.toJSONString(model);
    assertEquals("{\"_id\":1001,\"id\":1002}", json);
    Model model1 = JSON.parseObject(json, Model.class);
    assertEquals(json, JSON.toJSONString(model1));
}
 
Example 6
Project: GitHub   File: StringBufferFieldTest.java   Source Code and License Vote up 5 votes
public void test_deserialize_1() throws Exception {
    String json = "{\"value\":\"\"}";

    V0 vo = JSON.parseObject(json, V0.class);
    Assert.assertNotNull(vo.getValue());
    Assert.assertEquals("", vo.getValue().toString());
}
 
Example 7
Project: GitHub   File: JSONCreatorTest.java   Source Code and License Vote up 5 votes
public void test_create() throws Exception {
    Entity entity = new Entity(123, "菜姐");
    String text = JSON.toJSONString(entity);
    
    Entity entity2 = JSON.parseObject(text, Entity.class);
    Assert.assertEquals(entity.getId(), entity2.getId());
    Assert.assertEquals(entity.getName(), entity2.getName());
}
 
Example 8
Project: pay-xxpay-master   File: PayOrderServiceController.java   Source Code and License Vote up 5 votes
@RequestMapping(value = "/pay/query")
public String queryPayOrder(@RequestParam String jsonParam) {
    _log.info("selectPayOrder << {}", 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 mchId = paramObj.getString("mchId");
    String payOrderId = paramObj.getString("payOrderId");
    String mchOrderNo = paramObj.getString("mchOrderNo");
    PayOrder payOrder;
    if(StringUtils.isNotBlank(payOrderId)) {
        payOrder = payOrderService.selectPayOrderByMchIdAndPayOrderId(mchId, payOrderId);
    }else {
        payOrder = payOrderService.selectPayOrderByMchIdAndMchOrderNo(mchId, mchOrderNo);
    }
    if(payOrder == null) {
        retObj.put("code", "0002");
        retObj.put("msg", "支付订单不存在");
        return retObj.toJSONString();
    }

    //
    boolean executeNotify = paramObj.getBooleanValue("executeNotify");
    // 如果选择回调且支付状态为支付成功,则回调业务系统
    if(executeNotify && payOrder.getStatus() == PayConstant.PAY_STATUS_SUCCESS) {
        this.doNotify(payOrder);
    }
    retObj.put("result", JSON.toJSON(payOrder));
    _log.info("selectPayOrder >> {}", retObj);
    return retObj.toJSONString();
}
 
Example 9
Project: GitHub   File: StackTraceElementDeserializerTest.java   Source Code and License Vote up 5 votes
public void test_stack_error_3() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("{\"@type\":int}", StackTraceElement.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 10
Project: ucar-weex-core   File: WXModalUIModule.java   Source Code and License Vote up 5 votes
@JSMethod(uiThread = true)
public void toast(String param) {

  String message = "";
  int duration = Toast.LENGTH_SHORT;
  if (!TextUtils.isEmpty(param)) {
    try {
      param = URLDecoder.decode(param, "utf-8");
      JSONObject jsObj = JSON.parseObject(param);
      message = jsObj.getString(MESSAGE);
      duration = jsObj.getInteger(DURATION);
    } catch (Exception e) {
      WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
    }
  }
  if (TextUtils.isEmpty(message)) {
    WXLogUtils.e("[WXModalUIModule] toast param parse is null ");
    return;
  }

  if (duration > 3) {
    duration = Toast.LENGTH_LONG;
  } else {
    duration = Toast.LENGTH_SHORT;
  }
  if (toast == null) {
    toast = Toast.makeText(mWXSDKInstance.getContext(), message, duration);
  } else {
    toast.setDuration(duration);
    toast.setText(message);
  }
  toast.setGravity(Gravity.CENTER, 0, 0);
  toast.show();
}
 
Example 11
Project: GitHub   File: BooleanFieldTest_array.java   Source Code and License Vote up 5 votes
public void test_model_error_fa() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("[fa", Model.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 12
Project: GitHub   File: ByteBenchmark_obj.java   Source Code and License Vote up 5 votes
public static void perf() {
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000 * 1000 * 10; ++i) {
        JSON.parseObject(json, Model.class);
    }
    long millis = System.currentTimeMillis() - start;
    System.out.println("millis : " + millis);
}
 
Example 13
Project: GitHub   File: BooleanObjectFieldTest.java   Source Code and License Vote up 4 votes
public void test_0 () throws Exception {
    VO vo = JSON.parseObject("{\"value\":true}", VO.class);
    Assert.assertTrue(vo.value);
}
 
Example 14
Project: GitHub   File: ListStringFieldTest_dom_treeSet.java   Source Code and License Vote up 4 votes
public void test_empty() throws Exception {
    String text = "{\"values\":[]}";
    Model model = JSON.parseObject(text, Model.class);
    Assert.assertEquals(0, model.values.size());
}
 
Example 15
Project: GitHub   File: FloatNullTest.java   Source Code and License Vote up 4 votes
public void test_null() throws Exception {
    Model model = JSON.parseObject("{\"v1\":null,\"v2\":null}", Model.class);
    assertNotNull(model);
    assertNull(model.v1);
    assertNull(model.v2);
}
 
Example 16
Project: GitHub   File: DateTest_dotnet_3.java   Source Code and License Vote up 4 votes
public void test_date() throws Exception {
    String text = "{\"date\":\"/Date(1461081600321+0500)/\"}";

    Model model = JSON.parseObject(text, Model.class);
    Assert.assertEquals(1461081600321L, model.date.getTime());
}
 
Example 17
Project: GitHub   File: Bug_for_builder.java   Source Code and License Vote up 4 votes
public void test_for_longBuilderMethod() throws Exception {
    VO vo = JSON.parseObject("{\"id\":123}", VO.class);
}
 
Example 18
Project: letv   File: AlipayAutoSignMaintainParser.java   Source Code and License Vote up 4 votes
public AlipayAutoPayMaintainBean parse(JSONObject data) throws JSONException {
    AlipayAutoPayMaintainBean alipayAutoPayMaintainBean = new AlipayAutoPayMaintainBean();
    return (AlipayAutoPayMaintainBean) JSON.parseObject(data.getString("result"), AlipayAutoPayMaintainBean.class);
}
 
Example 19
Project: aliyun-cloudphotos-android-demo   File: RenameFaceRequest.java   Source Code and License Vote up 4 votes
@Override
public BaseResponse parse(String result) {
    return JSON.parseObject(result, RenameFaceResponse.class);
}
 
Example 20
Project: GitHub   File: LocalDateTest.java   Source Code and License Vote up 3 votes
public void test_for_issue() throws Exception {
    VO vo = new VO();
    vo.setDate(LocalDate.now());
    
    String text = JSON.toJSONString(vo);
    
    VO vo1 = JSON.parseObject(text, VO.class);
    
    Assert.assertEquals(vo.getDate(), vo1.getDate());
}