Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
bug fixed for jsonpath reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jun 28, 2019
1 parent c9abb11 commit c4c39ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.59_preview_06</version>
<version>1.2.59_preview_07</version>

<packaging>jar</packaging>
<name>fastjson</name>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/alibaba/fastjson/JSONPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -3893,8 +3893,10 @@ public static Object reserveToObject(Object object, String... paths) {
path.init();
Segment lastSegement = path.segments[path.segments.length - 1];
if (lastSegement instanceof PropertySegment) {
PropertySegment propertySegment = (PropertySegment) lastSegement;
Object value = path.eval(object);
if (value == null) {
continue;
}
path.set(reserved, value);
} else {
// skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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").toString());
assertEquals("{\"player\":{\"name\":\"ljw\",\"id\":1001}}", JSONPath.reserveToObject(object, "player.name", "player.id", "ab.c").toString());
}


Expand Down

0 comments on commit c4c39ac

Please sign in to comment.