use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPObjectTest method test_jsonp.
public void test_jsonp() throws Exception {
JSONPObject jsonp = new JSONPObject("checkValid");
jsonp.addParameter(new HashMap<String, Object>());
jsonp.addParameter(new ArrayList<Object>());
String text = jsonp.toString();
Assert.assertEquals("checkValid({},[])", text);
}
use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPParseTest method test_f.
public void test_f() throws Exception {
String text = "callback ({'id':1, 'name':'idonans'} );";
JSONPObject jsonpObject = JSON.parseObject(text, JSONPObject.class);
assertEquals("callback", jsonpObject.getFunction());
assertEquals(1, jsonpObject.getParameters().size());
JSONObject param = (JSONObject) jsonpObject.getParameters().get(0);
assertEquals(1, param.get("id"));
assertEquals("idonans", param.get("name"));
String json = JSON.toJSONString(jsonpObject);
System.out.println(json);
}
use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPParseTest2 method test_f.
public void test_f() throws Exception {
String text = "parent.callback ({'id':1, 'name':'idonans'} ); /**/ ";
JSONPObject jsonpObject = JSON.parseObject(text, JSONPObject.class);
assertEquals("parent.callback", jsonpObject.getFunction());
assertEquals(1, jsonpObject.getParameters().size());
JSONObject param = (JSONObject) jsonpObject.getParameters().get(0);
assertEquals(1, param.get("id"));
assertEquals("idonans", param.get("name"));
String json = JSON.toJSONString(jsonpObject, SerializerFeature.MapSortField);
assertEquals("parent.callback({\"id\":1,\"name\":\"idonans\"})", json);
}
use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPParseTest4 method test_f.
public void test_f() throws Exception {
JSONPObject p = new JSONPObject();
p.setFunction("f");
assertEquals("f()", p.toJSONString());
}
use of com.alibaba.fastjson.JSONPObject in project fastjson by alibaba.
the class JSONPParseTest1 method test_f.
public void test_f() throws Exception {
String text = "callback /**/ ({'id':1, 'name':'idonans'} ); ";
JSONPObject jsonpObject = JSON.parseObject(text, JSONPObject.class);
assertEquals("callback", jsonpObject.getFunction());
assertEquals(1, jsonpObject.getParameters().size());
JSONObject param = (JSONObject) jsonpObject.getParameters().get(0);
assertEquals(1, param.get("id"));
assertEquals("idonans", param.get("name"));
String json = JSON.toJSONString(jsonpObject);
System.out.println(json);
}
Aggregations