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

fix: Deserialize using a generic approach. #121

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

fujie-xiyou
Copy link
Contributor

Deserialize using generics. The previous deserialization method had issues in generic scenarios.

@fujie-xiyou
Copy link
Contributor Author

fujie-xiyou commented Jul 3, 2023

There is currently a known issue where the threadUnsafeSet type was changed to a non-pointer type in version 2.2.0. As a result, when using the json.Unmarshal function to deserialize the threadUnsafeSettype, an error occurs and it cannot correctly enter the UnmarshalJSONmethod of threadUnsafeSet. However, directly calling the UnmarshalJSON method can successfully deserialize it.

@fujie-xiyou
Copy link
Contributor Author

One more question, currently threadSafeSet and threadUnsafeSet structs are not exported. When a struct includes a set.Set type, json.Unmarshal cannot be used to deserialize the struct. Could you please let me know if it's possible to make threadSafeSet and threadUnsafeSet exportable so that they can be used in this scenario?

@deckarep
Copy link
Owner

Deserialize using generics. The previous deserialization method had issues in generic scenarios.

Can you be more specific what the issue was? I personally don't use the Marshal/Unmarshal too much but to my knowledge the tests were all previously passing.

@deckarep
Copy link
Owner

One more question, currently threadSafeSet and threadUnsafeSet structs are not exported. When a struct includes a set.Set type, json.Unmarshal cannot be used to deserialize the struct. Could you please let me know if it's possible to make threadSafeSet and threadUnsafeSet exportable so that they can be used in this scenario?

I'd rather ideally rather not export them because the Set interface is the type user's should be working with. Please provide a code example of what doesn't work.

@deckarep
Copy link
Owner

There is currently a known issue where the threadUnsafeSet type was changed to a non-pointer type in version 2.2.0. As a result, when using the json.Unmarshal function to deserialize the threadUnsafeSettype, an error occurs and it cannot correctly enter the UnmarshalJSONmethod of threadUnsafeSet. However, directly calling the UnmarshalJSON method can successfully deserialize it.

Is this what your PR fixes? Or is this a separate issue. I would be more inclined to expedite this work if we can get a issue/PR created per issue that you are having.

@fujie-xiyou
Copy link
Contributor Author

fujie-xiyou commented Jul 25, 2023

Deserialize using generics. The previous deserialization method had issues in generic scenarios.

Can you be more specific what the issue was? I personally don't use the Marshal/Unmarshal too much but to my knowledge the tests were all previously passing.

The current test for Marshal/Unmarshal only includes tests for the string type. When the element type of the set is int64, you can refer to this code snippet. In reality, it cannot be deserialized successfully as expected. This pull request fixes the issue. With this correction, deserialization of int64 elements works correctly.

@deckarep deckarep merged commit b20691d into deckarep:main Aug 2, 2023
3 checks passed
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