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
@Data @NoArgsConstructor @AllArgsConstructor public class ApproveConfigJson implements Serializable { private String postId; private boolean hasPreNode = false; private ApproveConfigJson preNode; private boolean hasNextNode = false; private ApproveConfigJson nextNode; private int sort; public ApproveConfigJson(String postId, int sort) { this.postId = postId; this.sort = sort; } } public static void main(String[] args) { List<ApproveConfigJson> approveConfigJsons = new ArrayList<>(); approveConfigJsons.add(new ApproveConfigJson("1",1)); approveConfigJsons.add(new ApproveConfigJson("2",2)); approveConfigJsons.add(new ApproveConfigJson("3",3)); String s = list2LinkedJson2(approveConfigJsons); ApproveConfigJson approveConfigJson = JSON.parseObject(s, ApproveConfigJson.class); System.err.println(approveConfigJson.getNextNode().getPreNode().getPostId()); } public static String list2LinkedJson2(List<ApproveConfigJson> approveConfigJsons) { approveConfigJsons = approveConfigJsons.stream().sorted(Comparator.comparing(ApproveConfigJson::getSort)).collect(Collectors.toList()); ApproveConfigJson approveUtil = null; Iterator<ApproveConfigJson> iterator = approveConfigJsons.iterator(); ApproveConfigJson local = new ApproveConfigJson(); while (iterator.hasNext()) { ApproveConfigJson next = iterator.next(); if (approveUtil == null) { approveUtil = next; local = next; } else { approveUtil.setHasNextNode(true); approveUtil.setNextNode(next); next.setHasPreNode(true); next.setPreNode(local); local = next; approveUtil = approveUtil.getNextNode(); approveUtil.setNextNode(null); } } ApproveConfigJson finalNode = approveUtil; while (finalNode.isHasPreNode()) { finalNode = finalNode.getPreNode(); } return JSON.toJSONString(finalNode); }
按照sort排序,链表首节点为postId = 1,序列化的json串正常,但是反序列化后链表的首节点为postId = 2,且获取下级节点后再获取上级节点会出现java.lang.NullPointerException 在 ApproveConfigJson approveConfigJson = JSON.parseObject(s, ApproveConfigJson.class);方法中
The text was updated successfully, but these errors were encountered:
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.6-SNAPSHOT/
感谢反馈了JSON格式支持引用的BUG,问题已修复,请用2.0.6-SNAPSHOT版本验证。2.0.6正式版本预计6月5日前发布。
Sorry, something went wrong.
https://github.com/alibaba/fastjson2/releases/tag/2.0.6 问题已经修复,请用新版本
No branches or pull requests
按照sort排序,链表首节点为postId = 1,序列化的json串正常,但是反序列化后链表的首节点为postId = 2,且获取下级节点后再获取上级节点会出现java.lang.NullPointerException
在 ApproveConfigJson approveConfigJson = JSON.parseObject(s, ApproveConfigJson.class);方法中
The text was updated successfully, but these errors were encountered: