package com.alibaba.json.bvt.jsonp;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

/**
 * Created by wenshao on 21/02/2017.
 */
public class JSONPParseTest2 extends TestCase {
    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);
        assertEquals("parent.callback({\"name\":\"idonans\",\"id\":1})", json);
    }
}

@@ -884,16 +884,48 @@
 npObject
+, SerializerFeature.MapSortField
 );%0A     
@@ -960,16 +960,25 @@
 back(%7B%5C%22
+id%5C%22:1,%5C%22
 name%5C%22:%5C
@@ -991,17 +991,8 @@
 ns%5C%22
-,%5C%22id%5C%22:1
 %7D)%22,

enable SerializeFeature.MapSortField for deterministic order