diff --git a/src/test/java/com/alibaba/json/bvt/path/JSONPath_reverse_test.java b/src/test/java/com/alibaba/json/bvt/path/JSONPath_reverse_test.java index 423a906a98..c5ed175b48 100644 --- a/src/test/java/com/alibaba/json/bvt/path/JSONPath_reverse_test.java +++ b/src/test/java/com/alibaba/json/bvt/path/JSONPath_reverse_test.java @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONPath; +import com.alibaba.fastjson.serializer.SerializerFeature; import junit.framework.TestCase; public class JSONPath_reverse_test extends TestCase @@ -12,7 +13,13 @@ public void test_reserve() throws Exception { assertEquals("[1001,\"ljw\"]", JSONPath.reserveToArray(object, "id", "name").toString()); assertEquals("[\"ljw\",1001]", JSONPath.reserveToArray(object, "name", "id").toString()); - assertEquals("[\"ljw\",[\"ljw\",1001,50]]", JSONPath.reserveToArray(object, "name", "*").toString()); + String text = JSON.toJSONString(JSONPath.reserveToArray(object, "name", "*"), SerializerFeature.MapSortField); + assertTrue(text.equals("[\"ljw\",[\"ljw\",1001,50]]") + || text.equals("[\"ljw\",[\"ljw\",50,1001]]") + || text.equals("[\"ljw\",[50,1001,\"ljw\"]]") + || text.equals("[\"ljw\",[1001,50,\"ljw\"]]") + || text.equals("[\"ljw\",[1001,\"ljw\",50]]") + || text.equals("[\"ljw\",[50,\"ljw\",1001]]")); } public void test_reserve2() throws Exception { @@ -26,8 +33,10 @@ public void test_reserve2() throws Exception { public void test_reserve3() throws Exception { JSONObject object = JSON.parseObject("{\"player\":{\"id\":1001,\"name\":\"ljw\",\"age\":50}}"); - assertEquals("{\"player\":{\"name\":\"ljw\",\"id\":1001}}", JSONPath.reserveToObject(object, "player.id", "player.name").toString()); - assertEquals("{\"player\":{\"name\":\"ljw\",\"id\":1001}}", JSONPath.reserveToObject(object, "player.name", "player.id", "ab.c").toString()); + String text = JSON.toJSONString(JSONPath.reserveToObject(object, "player.id", "player.name"), SerializerFeature.MapSortField); + assertEquals("{\"player\":{\"id\":1001,\"name\":\"ljw\"}}", text); + text = JSON.toJSONString(JSONPath.reserveToObject(object, "player.name", "player.id", "ab.c"), SerializerFeature.MapSortField); + assertEquals("{\"player\":{\"id\":1001,\"name\":\"ljw\"}}", text); }