Comments (4)
@fabriziosestito - release 2.3.1 has been pushed. Let me know if this satisfies your fix.
@fujie-xiyou - thanks for the fix. The other issues that you mentioned in the email should all be tracked as independent Issues/PR's if you feel strongly that other things need to get addressed.
from golang-set.
@deckarep Unfortunately the bug is still here.
You can check by running https://go.dev/play/p/WgjZEwrHk5U with 2.3.1.
The PR from @fujie-xiyou solves another problem about deserialization with generics.
I think the confusion came from the comments in the PR mentioning this particular issue with the UnmarshalJSON.
The only solution I see here is to go back to pointer receivers, otherwise, UnmarshalJSON will not work as it needs to mutate the data.
I cannot re-open this issue.
from golang-set.
@fabriziosestito - ok I am reopening and will look into a solution as my time permits.
from golang-set.
I finally got around to looking into this: It's a somewhat nasty bug and the best explanation I have so far: pretty much in all cases when the UnmarshalJSON
interface is implemented it must be implemented on a pointer
-based receiver. The json decoder needs to be able to reassign what it points in some cases so this is a hard requirement. Currently to satisfy it being implemented on the Set interface it's established as a value receiver for the threadUnsafe
flavor, after a somewhat recent refactor as @fabriziosestito noticed.
As it stands, although the test case involved, as posted in the playground link; takes the address of the set object which is a generic interface, the decoder isn't able to resolve that the UnmarshalJSON
exists on a pointer-based receiver because it is indeed not present.
Changing the test to explicitly use the UnmarshalJSON
method by calling: data.UnmarshalJSON
fixes the issue (as a workaround) but having it called via: json.Unmarshal
indirectly is where the failure happens.
I don't know how often folks are using the Set with encoding/decoding JSON but I'm curious how others might feel.
As it stands there is a very simple workaround.
Otherwise, I think the only option is to go back to moving the entirety of all threadUnsafe
set methods to be pointer based as it was before. This will fix the issue at the cost of having the slightest more overhead due to extra indirection.
from golang-set.
Related Issues (20)
- Missing support Len()/Count()/Size() method? HOT 2
- iterate with random sequence? HOT 1
- Feature request: Support for immutable sets HOT 1
- [Q] How to print the contents of a Set? HOT 1
- Getting error when instantiating a set: "invalid operation: cannot index mapset.NewSet (value of type func(s ...interface{}) mapset.Set)" HOT 6
- No installation guide
- [Question] Contains() parameters escape to heap HOT 4
- How I can get every elements in my set? HOT 2
- Document thread-safe set usage HOT 1
- Issue: Contains HOT 2
- [Question] Why isn't `defer` used? HOT 6
- Non-mutating helpers to add/remove HOT 2
- Guidance/suggestions on Iterators and Stop() HOT 4
- Add a way to distinguish thread safe and unsafe sets HOT 3
- Is there any method to know whether a set is empty? HOT 2
- unmarshal json fails when set is part of struct HOT 2
- Suggestion: option to restrict comparable to only exported values. HOT 1
- why isn't there a `mapset.NewSetFromSlice` method? HOT 1
- Allow capacity to be specified when initializing a Set HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from golang-set.