Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved jsonpath support. fixed issue #735
- Loading branch information
Showing
6 changed files
with
137 additions
and
6 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
package com.alibaba.json.bvt.path; | |||
|
|||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONPath; | |||
|
|||
import junit.framework.TestCase; | |||
|
|||
public class JSONPath_4 extends TestCase { | |||
|
|||
public void test_path() throws Exception { | |||
String a = "{\"key\":\"value\",\"10.0.1.1\":\"haha\"}"; | |||
Object x = JSON.parse(a); | |||
System.out.println(JSON.toJSONString(x)); | |||
JSONPath.set(x, "$.test", "abc"); | |||
Object o = JSONPath.eval(x, "$.10\\.0\\.1\\.1"); | |||
} | |||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/com/alibaba/json/bvt/path/JSONPath_enum.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
package com.alibaba.json.bvt.path; | |||
|
|||
import org.junit.Assert; | |||
|
|||
import com.alibaba.fastjson.JSONPath; | |||
|
|||
import junit.framework.TestCase; | |||
|
|||
public class JSONPath_enum extends TestCase { | |||
|
|||
public void test_name() throws Exception { | |||
Model model = new Model(); | |||
model.size = Size.Small; | |||
|
|||
Assert.assertEquals(Size.Small.name(), JSONPath.eval(model, "$.size.name")); | |||
} | |||
|
|||
public void test_orginal() throws Exception { | |||
Model model = new Model(); | |||
model.size = Size.Small; | |||
|
|||
Assert.assertEquals(Size.Small.ordinal(), JSONPath.eval(model, "$.size.ordinal")); | |||
} | |||
|
|||
public static class Model { | |||
public Size size; | |||
} | |||
|
|||
public static enum Size { | |||
Big, Median, Small | |||
} | |||
} |
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
19 changes: 19 additions & 0 deletions
19
src/test/java/com/alibaba/json/bvt/path/JSONPath_map_size.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
package com.alibaba.json.bvt.path; | |||
|
|||
import java.util.Collections; | |||
|
|||
import org.junit.Assert; | |||
|
|||
import com.alibaba.fastjson.JSONPath; | |||
|
|||
import junit.framework.TestCase; | |||
|
|||
public class JSONPath_map_size extends TestCase { | |||
public void test_list_size() throws Exception { | |||
Assert.assertEquals(0, JSONPath.eval(Collections.emptyMap(), "$.size")); | |||
} | |||
|
|||
public void test_list_size1() throws Exception { | |||
Assert.assertEquals(0, JSONPath.eval(Collections.emptyMap(), "$.size()")); | |||
} | |||
} |