We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fastjson中的@JSONField with unwrapped 异常,compared with fastjson2.
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONPath; import com.alibaba.fastjson2.annotation.JSONField; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; public class MutatedIssue897_44 { @Test public void test() { String json = "{\"name\": \"zhangsan\", \"age\": 18}"; People p = JSON.parseObject(json, People.class); assertEquals("zhangsan", p.getName()); assertEquals(18, p.getExtra().get("age")); JSONPath.set(p, "$.age", 20); assertEquals(20, p.getExtra().get("age")); } static class People { private String name; private Map<String, Object> extra = new HashMap<>(); public String getName() { return name; } public void setName(String name) { this.name = name; } public Map<String, Object> getExtra() { return extra; } public void setExtra(Map<String, Object> extra) { this.extra = extra; } @JSONField(unwrapped = true) public void set(String key, Object value) { this.extra.put(key, value); } @JSONField(unwrapped = true) public Object get(String key) { return this.extra.get(key); } } @Test public void testfj() { String json = "{\"name\": \"zhangsan\", \"age\": 18}"; People1 p = com.alibaba.fastjson.JSON.parseObject(json, People1.class); assertEquals("zhangsan", p.getName()); assertEquals(18, p.getExtra().get("age")); com.alibaba.fastjson.JSONPath.set(p, "$.age", 20); assertEquals(20, p.getExtra().get("age")); } static class People1 { private String name; private Map<String, Object> extra = new HashMap<>(); public String getName() { return name; } public void setName(String name) { this.name = name; } public Map<String, Object> getExtra() { return extra; } public void setExtra(Map<String, Object> extra) { this.extra = extra; } @com.alibaba.fastjson.annotation.JSONField(unwrapped = true) public void set(String key, Object value) { this.extra.put(key, value); } @com.alibaba.fastjson.annotation.JSONField(unwrapped = true) public Object get(String key) { return this.extra.get(key); } } }
正常解析
Expected :18 Actual :null
The text was updated successfully, but these errors were encountered:
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.50-SNAPSHOT/ 问题已修复,请帮忙用2.0.50-SNAPSHOT版本验证下
Sorry, something went wrong.
fix fastjson 1.x JSONField#unwrapped not work, for issue #2551
8dee60c
验证已修复,辛苦wenshao
https://github.com/alibaba/fastjson2/releases/tag/2.0.50 2.0.50已发布,请用新版本
No branches or pull requests
问题描述
Fastjson中的@JSONField with unwrapped 异常,compared with fastjson2.
环境信息
重现步骤
期待的正确结果
正常解析
相关日志输出
Expected :18
Actual :null
The text was updated successfully, but these errors were encountered: