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
简要描述您碰到的问题。 JSON将map转成Java对象出现类型转换未达预期的问题
请填写以下信息:
public class Main { public static void main(String[] args) { String json = "{\"name\":\"希望小学\",\"students\":{\"age\":\"12\",\"id\":\"1\",\"name\":\"张宇\"}}"; School schoolOne = JSON.parseObject(json, School.class); JSONObject schoolTwo = JSON.parseObject(json); School schoolThree = schoolTwo.toJavaObject(School.class); JSONObject studentOne = schoolTwo.getJSONObject("students"); JSONArray studentTwo = schoolTwo.getJSONArray("students"); System.out.println(studentTwo.toString()); } @Data private static class School{ private String name; private List<Student> students; } @Data private static class Student{ private String name; private String id; private String age; } }
对于fastjson能够将对象根据目标类型自动转换成array我是认可的,希望能够保留这个特性,对于那些不期望这个特性的可以加一个参数允许关闭这个特性。 说回正题,如图所示schoolOne ,schoolTwo ,studentOne 和studentTwo 是符合预期的转换,但是schoolThree 却未达到预期,经过转换后内部的students数据丢失了,数组大小为0,期望的结果是能够根据目标类型,将map转成对象数组。 如果这个功能一开始就不支持也就罢了,经过测试,json字符串直接解析是可以正常转换,而通过map进行转换缺不能达到预期,希望二者能够保持一致
The text was updated successfully, but these errors were encountered:
fix parse private class error, for issue #3134
e07d013
https://github.com/alibaba/fastjson2/releases/tag/2.0.54 问题已修复,请用新版本
Sorry, something went wrong.
No branches or pull requests
问题描述
简要描述您碰到的问题。
JSON将map转成Java对象出现类型转换未达预期的问题
环境信息
请填写以下信息:
重现步骤
期待的正确结果
对于fastjson能够将对象根据目标类型自动转换成array我是认可的,希望能够保留这个特性,对于那些不期望这个特性的可以加一个参数允许关闭这个特性。
说回正题,如图所示schoolOne ,schoolTwo ,studentOne 和studentTwo 是符合预期的转换,但是schoolThree 却未达到预期,经过转换后内部的students数据丢失了,数组大小为0,期望的结果是能够根据目标类型,将map转成对象数组。
如果这个功能一开始就不支持也就罢了,经过测试,json字符串直接解析是可以正常转换,而通过map进行转换缺不能达到预期,希望二者能够保持一致
The text was updated successfully, but these errors were encountered: