-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix name for Issue2640 test * fix fastjson 1.x jsonpath compatible api return fastjson 2 JSONObject and JSONArrary, for #2759
- Loading branch information
1 parent
334d256
commit 2323874
Showing
4 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue2748.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.alibaba.fastjson.v2issues; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONPath; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2748 { | ||
@Test | ||
public void test() { | ||
User user = JSON.parseObject(str, User.class); | ||
JSONArray result = (JSONArray) JSONPath.eval(user, "$.phoneNumbers[?(@.address.city == 'Nara1')]"); | ||
assertEquals(1, result.size()); | ||
} | ||
|
||
public static class User { | ||
public String firstName; | ||
public String lastName; | ||
public int age; | ||
public List<PhoneNumber> phoneNumbers; | ||
} | ||
|
||
public static class Address { | ||
public String streetAddress; | ||
public String city; | ||
public String postalCode; | ||
} | ||
|
||
public static class PhoneNumber { | ||
public String type; | ||
public String number; | ||
public Address address; | ||
} | ||
|
||
static String str = "{ \"firstName\": \"John\", \"lastName\" : \"doe\", \"age\" : 26, \"address\" : { \"streetAddress\": \"naist street\", \"city\" : \"Nara\", \"postalCode\" : \"630-0192\" }, \"phoneNumbers\": [ { \"type\" : \"iPhone\", \"number\": \"0123-4567-8888\", \"address\" : { \"streetAddress\": \"naist street1\", \"city\" : \"Nara1\", \"postalCode\" : \"630-0192\" } }, { \"type\" : \"home\", \"number\": \"0123-4567-8910\", \"address\" : { \"streetAddress\": \"naist street2\", \"city\" : \"Nara2\", \"postalCode\" : \"630-0192\" } } ] }"; | ||
} |
25 changes: 25 additions & 0 deletions
25
fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue2759.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.alibaba.fastjson.v2issues; | ||
|
||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.JSONPath; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class Issue2759 { | ||
@Test | ||
public void test1() { | ||
String raw = "[[{\"a\":1},{\"a\":2}],[{\"a\":3}]]"; | ||
assertEquals("{\"a\":2}", ((JSONObject) JSONPath.eval(raw, "$[0][1]")).toJSONString()); | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
String testJson2 = "{\"result\":[{\"puid\":\"21025318\"},{\"puid\":\"21482682\"},{\"puid\":\"21025345\"}],\"state\":0}"; | ||
JSONArray result2 = (JSONArray) JSONPath.eval(testJson2, "$.result[0,2].puid"); | ||
assertNotNull(result2); | ||
assertEquals("[\"21025318\",\"21025345\"]", result2.toJSONString()); | ||
} | ||
} |