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

建议添加字段初始化函数接口 #714

Closed
Nyx2022 opened this issue Nov 24, 2024 · 1 comment
Closed

建议添加字段初始化函数接口 #714

Nyx2022 opened this issue Nov 24, 2024 · 1 comment

Comments

@Nyx2022
Copy link

Nyx2022 commented Nov 24, 2024

我在一个复杂的struct中,如果使用了除golang自带类型之外,就会没办法提前初始化变量,而sonic又会自动去反射调用对应库的marshaljson和unmarshaljson,这个时候就会出错(因为不是每一个第三方库都只需要实例化结构体就行,里面会有很多不暴露的属性需要初始化),所以建议添加一个接口或函数,比如withInitFuncs,由用户传递一个sonic在反序列化过程中发现字段为nil的时候,先调用初始化函数,再调用unmarshaljson函数。谢谢

@AsterDY
Copy link
Collaborator

AsterDY commented Dec 2, 2024

obj不是你传给sonic的么?为啥不能在调用unmarshal之前先设置好没理解

@Nyx2022 Nyx2022 closed this as completed Dec 3, 2024
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

No branches or pull requests

2 participants