Skip to content
New issue

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

设置safeMode=true后AutoType的转换问题 #1503

Closed
Allen123Hao opened this issue May 21, 2023 · 2 comments
Closed

设置safeMode=true后AutoType的转换问题 #1503

Allen123Hao opened this issue May 21, 2023 · 2 comments
Labels
fixed question Further information is requested
Milestone

Comments

@Allen123Hao
Copy link

当vm设置-Dfastjson2.parser.safeMode=true后不支持AutoType没问题,但是设置了JSONReader.autoTypeFilter后,转换的对象也会丢失子类的属性,请问怎么回事?
Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter("org.example.model");
String json = JSON.toJSONString(versionInfo,
JSONWriter.Feature.WriteClassName);
System.out.println(json);
VersionInfo versionInfo1 = JSON.parseObject(bytes,VersionInfo.class,AUTO_TYPE_FILTER);
System.out.println(JSON.toJSONString(versionInfo1));
打印结果:
{"appVersion":{"@type":"org.example.model.CustomerAppVersion","appVersion":"v1.1.0","platform":1},"userName":"Allen","version":"v1"}
{"appVersion":{"appVersion":"v1.1.0"},"userName":"Allen","version":"v1"}
反序列化丢失了platform属性。

@Allen123Hao Allen123Hao added the question Further information is requested label May 21, 2023
@Allen123Hao Allen123Hao changed the title AutoType转换为题 设置safeMode=true后AutoType的转换问题 May 21, 2023
@wenshao wenshao modified the milestone: 2.0.33 May 21, 2023
wenshao added a commit that referenced this issue May 21, 2023
@wenshao wenshao added this to the 2.0.33 milestone May 21, 2023
@wenshao
Copy link
Member

wenshao commented May 22, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.33-SNAPSHOT/
问题已修复,请帮忙用2.0.33-SNAPSHOT版本验证。

@wenshao wenshao added the fixed label May 22, 2023
@wenshao
Copy link
Member

wenshao commented May 29, 2023

@wenshao wenshao closed this as completed May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants