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

feat: support explictly null set in model(poc) #31

Draft
wants to merge 1 commit into
base: java-sdk-2.18.2-2025-01-06T07-06-06.523Z
Choose a base branch
from

Conversation

Sczlog
Copy link
Collaborator

@Sczlog Sczlog commented Jan 14, 2025

add ConditionalNullablePojo and type adapter

self test serialize and deserialize

image

@Sczlog Sczlog force-pushed the explictly-json branch 2 times, most recently from cca0cbd to cf610d6 Compare January 14, 2025 07:20
if (!field.canAccess(value)) {
field.setAccessible(true);
}
fieldValue = field.get(value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥 private field 还需要被序列化?我看常见的做法是只处理 public getter/setter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我试了一下,发现 getter 来获取其实不太方便,因为 getter 本质还是一个 function,没法准确的通过是否以 get 开头就是 getter 的逻辑来推断一个方法一定是 getter。。。
感觉通过 private field + annotation 判断的方法更加稳妥一点。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以看看 beanutils getProperty()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm,看了一下,是能解决如何推断 getter,但是我还需要 annotation 的 value orz

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不过我现在想我是不是该放弃反射,给每个类单独生成一个 Adapter

private final static String IS_PRESENT = "_isPresent_";

public static class ConditionalNullablePojo {
protected Set<String> _isPresent_ = new HashSet<String>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 _isPresent_ 是故意的吗,这个名字看着有点怪

Copy link
Collaborator Author

@Sczlog Sczlog Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免和潜在的可能字段冲突,用 _ 当 prefix 过滤一层,在自己这边不在 api 参数中定义 _ 前缀的字段

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants