Comments (5)
@sclasen - can you provide more details of what you are looking for? The set's backing structure is not an array so not sure what you mean exactly.
from golang-set.
Yeah thats what I mean, basically not exposing the underlying structure in serialization.
Closest thing you can get is a json array I think.
Currently serializing one of these sets to json would look something like
{"aSet": {"s": {"aMember": "", "anotherMember" : "", "aThirdMember": ""}}
where something like this would be much easier to consume
{"aSet": ["aMember", "anotherMember", "aThirdMember"]}
Not postive this is actually possible with go encoding/json thought....
from golang-set.
or actually since the threadunsafe set is private, it wouldnt get serialized at all.
from golang-set.
I have a simple MarshalJSON implemented, basically just a ToSlice wrapped in json.Marshal. Does the trick for me, but then again, I don't need the Unmarshal:
func (set *threadUnsafeSet) MarshalJSON() ([]byte, error) {
items := set.ToSlice()
return json.Marshal(items)
}
Feel free to use this if you feel so inclined.
from golang-set.
+1,
I need serializing these sets to json as well.
If @thorhs and @Aorioli's patch is good, please merge it.
UPDATE, @thorhs' method won't work for me, as I need to Unmarshal as well. So If @Aorioli's patch is good, please merge it.
Thanks
from golang-set.
Related Issues (20)
- 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
- Unmarshalling threadUnsafeSet with json.Unmarshal panics HOT 7
- 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 5
- 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
- Suggestion: Add comparator for structs HOT 4
- Support 1.23 iterator for set HOT 1
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.