arextest / arex-agent-java

Lightweight Java agent for traffic capture and replay, enhancing testing and debugging.
https://doc.arextest.com/
Apache License 2.0
444 stars 91 forks source link

[Bug] 反序列化时 null数据也会调用set方法 #448

Closed ZHFlys closed 4 months ago

ZHFlys commented 5 months ago

Search before asking

AREX Test Service

AREX Java Agent (arextest/arex-agent-java)

Current Behavior

入库时的属性为null 反序列时被set方法重新设置 导致回放失败

Expected Behavior

没设置的属性为null 序列化时不应该去调用set方法 set方法可能会影响反序列化其他属性 导致值不一致

Steps To Reproduce

类A属性 定义时 int a=1 int b setB(){a=2;} 反序列化时 默认的a=1没序列上 被2覆盖

Anything else

是不是主要更改 io.arex.foundation.serializer.jackson.JacksonSerializer#configMapper 方法

Are you willing to submit a pull request to fix on your own?

mr3 commented 4 months ago

@ZHFlys 感谢您在 AREX 社区反馈!

Jackson 库在反序列化 JSON 时的赋值逻辑主要基于 Java 对象的字段名或者setter 方法。

处理 null 值:默认情况下,如果 JSON 对象的某个属性的值为 null,反序列化时会将 Java 对象的对应字段设置为 null。但可以通过在字段或者 setter 方法上使用 @JsonInclude(Include.NON_NULL) 注解来忽略 null 值。

不建议设置全局忽略null值,这会引发在构造函数中初始化数据,在后续set null后导致序列化,反序列化不一致的情况。

mr3 commented 4 months ago

@ZHFlys This issue will be closed. If you have more infomation, please reopen and add it.