[QUESTION]JSON.toJSONString方法使用Filter后,子属性对象中的@type会缺失
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
使用JSON.toJSONString生成json时,用下面的方法会使子属性中的@type缺失,父属性中@type正常输出
JSON.toJSONString(epgUserVo, new Filter[]{ TOKEN_USER_PROPERTY_FILTER }, JSONWriter.Feature.WriteClassName)
{
"@type": "com.kd.epg.domain.vo.user.BaseEpgUserVo",
"endDate": "2023-10-10 22:32:28",
"epgInfoVo": {
"back_hall_url": "",
"TokenExpiretime": "20230926153828"....
}
}
epgInfoVo是子属性类,继承自HashMap,正常应该有 "@type":"com.kd.epg.domain.vo.user.impl.GuangxiEpgInfoVo",但是这里不会生成
去除filter后子属性的@type正常添加了:
JSON.toJSONString(epgUserVo, JSONWriter.Feature.WriteClassName)
{
"@type": "com.kd.epg.domain.vo.user.BaseEpgUserVo",
"endDate": "2023-10-10 22:50:36",
"epgInfoVo": {
"@type": "com.kd.epg.domain.vo.user.impl.GuangxiEpgInfoVo",
"back_hall_url": "",
"TokenExpiretime": "20230926153828".....
}
}
filter内容
PropertyFilter TOKEN_USER_PROPERTY_FILTER = (object, name, value) -> {
if ("epg_info".equals(name)) return false;
return true;
};
这个情况是否正常,或者正确写法应该是如何?
Contributor guide
Research direction
Start by reproducing the issue with JSON.toJSONString(epgUserVo, new Filter[]{ TOKEN_USER_PROPERTY_FILTER }, JSONWriter.Feature.WriteClassName), then compare it with serialization without the filter. Check how the PropertyFilter handling affects the nested epgInfoVo type metadata; done means determining whether the missing @type is expected or correcting the behavior and verifying the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100