use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPParseTest3 method test_f.
public void test_f() throws Exception {
String text = "parent.callback ({'id':1, 'name':'ido)nans'},1,2 ); /**/ ";
JSONPObject jsonpObject = (JSONPObject) JSON.parseObject(text, JSONPObject.class);
assertEquals("parent.callback", jsonpObject.getFunction());
assertEquals(3, jsonpObject.getParameters().size());
JSONObject param = (JSONObject) jsonpObject.getParameters().get(0);
assertEquals(1, param.get("id"));
assertEquals("ido)nans", param.get("name"));
String json = JSON.toJSONString(jsonpObject, SerializerFeature.BrowserSecure);
assertEquals("/**/parent.callback({\"name\":\"ido\\u0029nans\",\"id\":1},1,2)", json);
}
use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPObjectTest method test_jsonp_1.
public void test_jsonp_1() throws Exception {
JSONPObject jsonp = new JSONPObject();
jsonp.setFunction("checkValid");
jsonp.addParameter(new HashMap<String, Object>());
jsonp.addParameter(new ArrayList<Object>());
Assert.assertEquals("checkValid", jsonp.getFunction());
Assert.assertEquals(2, jsonp.getParameters().size());
String text = jsonp.toString();
Assert.assertEquals("checkValid({},[])", text);
Assert.assertEquals("checkValid({},[])", jsonp.toJSONString());
}
Aggregations