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
不同的注解方法结果不同。
如何操作可以重现该问题:
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.annotation.JSONField; import java.io.Serializable; import java.util.List; /** * fastjson2 新版本测试 */ public class JsonTest { /** * fastjson2 这种注解方式可以正常工作 */ public class User implements Serializable { @JSONField(name = "id") private int id; @JSONField(name = "title") private String title; @JSONField(name = "parent_id") private Integer parentId; @JSONField(name = "display_level") private Integer displayLevel; @JSONField(name = "item_index") private Integer itemIndex; @JSONField(name = "child_count") private Integer childCount; @JSONField(name = "phase_id") private Integer phaseId; @JSONField(name = "del_state") private int delState; @JSONField(name = "path") private String path; @JSONField(name = "update_time") private Long updateTime; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Integer getParentId() { return parentId; } public void setParentId(Integer parentId) { this.parentId = parentId; } public Integer getDisplayLevel() { return displayLevel; } public void setDisplayLevel(Integer displayLevel) { this.displayLevel = displayLevel; } public Integer getItemIndex() { return itemIndex; } public void setItemIndex(Integer itemIndex) { this.itemIndex = itemIndex; } public Integer getChildCount() { return childCount; } public void setChildCount(Integer childCount) { this.childCount = childCount; } public Integer getPhaseId() { return phaseId; } public void setPhaseId(Integer phaseId) { this.phaseId = phaseId; } public int getDelState() { return delState; } public void setDelState(int delState) { this.delState = delState; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public Long getUpdateTime() { return updateTime; } public void setUpdateTime(Long updateTime) { this.updateTime = updateTime; } } /** * fastjson2 这种方式会丢失字段信息。 * fastjson1 不会丢失信息 */ public class User2 implements Serializable { private int id; private String title; private Integer parentId; private Integer displayLevel; private Integer itemIndex; private Integer childCount; private Integer phaseId; private int delState; private String path; private Long updateTime; @JSONField(name = "id") public int getId() { return id; } public void setId(int id) { this.id = id; } @JSONField(name = "title") public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @JSONField(name = "parent_id") public Integer getParentId() { return parentId; } public void setParentId(Integer parentId) { this.parentId = parentId; } @JSONField(name = "display_level") public Integer getDisplayLevel() { return displayLevel; } public void setDisplayLevel(Integer displayLevel) { this.displayLevel = displayLevel; } @JSONField(name = "item_index") public Integer getItemIndex() { return itemIndex; } public void setItemIndex(Integer itemIndex) { this.itemIndex = itemIndex; } @JSONField(name = "child_count") public Integer getChildCount() { return childCount; } public void setChildCount(Integer childCount) { this.childCount = childCount; } @JSONField(name = "phase_id") public Integer getPhaseId() { return phaseId; } public void setPhaseId(Integer phaseId) { this.phaseId = phaseId; } @JSONField(name = "del_state") public int getDelState() { return delState; } public void setDelState(int delState) { this.delState = delState; } @JSONField(name = "path") public String getPath() { return path; } public void setPath(String path) { this.path = path; } @JSONField(name = "update_time") public Long getUpdateTime() { return updateTime; } public void setUpdateTime(Long updateTime) { this.updateTime = updateTime; } } public static void main(String[] args) { String text = "[{\"child_count\":8,\"del_state\":0,\"display_level\":2,\"id\":54,\"item_index\":46,\"parent_id\":1,\"path\":\"/1/54/\",\"phase_id\":1,\"title\":\"八年级上\",\"update_time\":1596423978669}]"; List<User> list1 = JSON.parseArray(text, User.class); if (list1 != null && list1.size() > 0) { User user = list1.get(0); System.out.println(JSON.toJSONString(user)); //这里的输出结果如下 // {"child_count":8,"del_state":0,"display_level":2,"id":54,"item_index":46,"parent_id":1,"path":"/1/54/","phase_id":1,"title":"八年级上","update_time":1596423978669} } text = "[{\"child_count\":8,\"del_state\":0,\"display_level\":2,\"id\":54,\"item_index\":46,\"parent_id\":1,\"path\":\"/1/54/\",\"phase_id\":1,\"title\":\"八年级上\",\"update_time\":1596423978669}]"; List<User2> list2 = JSON.parseArray(text, User2.class); if (list2 != null && list2.size() > 0) { User2 user2 = list2.get(0); System.out.println(JSON.toJSONString(user2)); //fastjson2 这里的输出结果如下, //{"del_state":0,"id":54,"path":"/1/54/","title":"八年级上"} //而fastjson1输出的结果是完整的, // {"child_count":8,"del_state":0,"display_level":2,"id":54,"item_index":46,"parent_id":1,"path":"/1/54/","phase_id":1,"title":"八年级上","update_time":1596423978669} } } }
运行环境: idea maven 项目,使用了spring framework,struts2
The text was updated successfully, but these errors were encountered:
improve fastjson 1.x compatible, parseArray config SupportSmartMatch …
11d8033
…default enabled, fix issue #454
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson/2.0.7-SNAPSHOT/ 问题已经修复,请帮忙用2.0.7-SNAPSHOT版本验证
Sorry, something went wrong.
好的,我先测试下,原来测试的使用兼容1的fastjson2和独立的fastjson2都存在此问题。下面2个地址的pom引用之后都出同样的问题 https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2/2.0.6 https://mvnrepository.com/artifact/com.alibaba/fastjson/2.0.6
是不是应该推荐使用独立的 fastjson2,兼容1的fastjson2只是过渡期间的版本吧,以后不会一直维护下去吧?
兼容的会一直维护下去
https://github.com/alibaba/fastjson2/releases/tag/2.0.7 问题已经修复,请用新版本
No branches or pull requests
问题描述
不同的注解方法结果不同。
环境信息
重现步骤
如何操作可以重现该问题:
运行环境:
idea maven 项目,使用了spring framework,struts2
The text was updated successfully, but these errors were encountered: