Search in sources :

Example 1 with JSONPObject

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);
}
Also used : JSONPObject(com.alibaba.fastjson.JSONPObject) JSONPObject(com.alibaba.fastjson.JSONPObject)

Example 2 with JSONPObject

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);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONPObject(com.alibaba.fastjson.JSONPObject)

Example 3 with JSONPObject

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);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONPObject(com.alibaba.fastjson.JSONPObject)

Example 4 with JSONPObject

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());
}
Also used : JSONPObject(com.alibaba.fastjson.JSONPObject)

Example 5 with JSONPObject

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);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONPObject(com.alibaba.fastjson.JSONPObject)

Aggregations

JSONPObject (com.alibaba.fastjson.JSONPObject)13 JSONObject (com.alibaba.fastjson.JSONObject)4 JSONException (com.alibaba.fastjson.JSONException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 E3Result (cn.e3mall.common.pojo.E3Result)1 SerializeFilter (com.alibaba.fastjson.serializer.SerializeFilter)1 ResponseJSONP (com.alibaba.fastjson.support.spring.annotation.ResponseJSONP)1 ArrayList (java.util.ArrayList)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1