-
Notifications
You must be signed in to change notification settings - Fork 479
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
[BUG] 反序列化时JSONObject字段出现{"h":{***}}结构 #2230
Comments
没复现, 你检查下哪里配置的不一致 public class Issue2230 {
@Test
void test(){
JSONObject dfDtoJson = new JSONObject();
dfDtoJson.put(
"componentList",
new JSONArray().fluentAdd(
new JSONObject().fluentPut(
"props",
new JSONObject()
.fluentPut("compTypeName", "test11")
.fluentPut("name", "test22")
)
)
);
DynFormDto newDfDto = dfDtoJson.toJavaObject(DynFormDto.class);
System.out.println(newDfDto.getComponentList().get(0).getProps());
}
@Data
static class DynFormDto {
private List<DynFormComponentDto> componentList;
private String notes;
}
@Data
static class DynFormComponentDto implements Serializable {
private JSONObject props; // 组件完整配置
// 这个方法会导致props字段反序列化结果出现{"h":{***}}结构
public DynFormComponentDto props(IFormComponent comp) {
this.props = (JSONObject) JSONObject.from(comp, JSONWriter.Feature.FieldBased);
return this;
}
}
interface IFormComponent {
String getCompTypeName();
String getName();
}
} |
@rowstop 你这个测试案例,多次运行,就会重现重来 |
@rowstop 多次运行你的案例,重新截图 |
给这个方法加上 @Data
static class DynFormComponentDto implements Serializable {
private JSONObject props; // 组件完整配置
// 这个方法会导致props字段反序列化结果出现{"h":{***}}结构
@JSONField(deserialize = false)
public DynFormComponentDto props(IFormComponent comp) {
this.props = JSONObject.from(comp, JSONWriter.Feature.FieldBased);
return this;
}
} |
请后续优化一下吧,添加@JSONField(deserialize = false)的方式,对代码有侵入性 |
rowstop
added a commit
to rowstop/fastjson2
that referenced
this issue
Feb 5, 2024
rowstop
added a commit
to rowstop/fastjson2
that referenced
this issue
Feb 5, 2024
…ith non-startsWith 'set',for issue alibaba#2230
3 tasks
wenshao
pushed a commit
that referenced
this issue
Feb 5, 2024
…ith non-startsWith 'set',for issue #2230
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
使用最新版本fastjson2 (2.0.46)将JSONObject对象反序列化为Java对象时,对于对象中的JSONObject字段,该字段会多出{"h":{***}}结构,与反序列化不一致
环境信息
fastjson2 版本:2.0.46
重现步骤
执行结果:
{"h":{"compTypeName":"test11","name":"test22"}}
正常应该为:
{"compTypeName":"test11","name":"test22"}
The text was updated successfully, but these errors were encountered: