Coder Social home page Coder Social logo

Comments (5)

deckarep avatar deckarep commented on August 19, 2024

@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.

sclasen avatar sclasen commented on August 19, 2024

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.

sclasen avatar sclasen commented on August 19, 2024

or actually since the threadunsafe set is private, it wouldnt get serialized at all.

from golang-set.

thorhs avatar thorhs commented on August 19, 2024

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.

suntong avatar suntong commented on August 19, 2024

+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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.