-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix for jsonpath set, for issue #3125
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
core/src/test/java/com/alibaba/fastjson2/issues_3100/Issue3125.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,50 @@ | ||
package com.alibaba.fastjson2.issues_3100; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONPath; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue3125 { | ||
@Getter | ||
@Setter | ||
static class User { | ||
private String name; | ||
private List<NVString> additionalInfo; | ||
} | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
static class NVString { | ||
String name; | ||
String value; | ||
} | ||
|
||
public static final String str = "{\"name\":\"fastjson2\",\"additionalInfo\":[{\"name\":\"srv6-color\",\"value\":\"test\"},{\"name\":\"test2\",\"value\":\"3\"}]}"; | ||
|
||
public static String path = "$.additionalInfo[?(@.name=='srv6-color')].value"; | ||
|
||
@Test | ||
public void test_fastjson2_case1() { | ||
User user = JSON.parseObject(str, User.class); | ||
JSONPath jsonPath = JSONPath.of("$.additionalInfo[?(@.name=='srv6-color')].value"); | ||
jsonPath.set(user, "modify"); | ||
assertEquals(user.getAdditionalInfo().get(0).getValue(), "modify"); | ||
} | ||
|
||
@Test | ||
public void test_fastjson_case1() { | ||
User user = JSON.parseObject(str, User.class); | ||
com.alibaba.fastjson.JSONPath.set(user, "$.additionalInfo[?(@.name=='srv6-color')].value", "modify"); | ||
JSONPath jsonPath = JSONPath.of("$.additionalInfo[?(@.name=='srv6-color')].value"); | ||
jsonPath.set(user, "modify"); | ||
assertEquals(user.getAdditionalInfo().get(0).getValue(), "modify"); | ||
} | ||
} |