bits-and-blooms / bitset

Go package implementing bitsets
BSD 3-Clause "New" or "Revised" License
1.32k stars 173 forks source link

Fix MarshalJSON not working for values #137

Closed lennart6443 closed 11 months ago

lennart6443 commented 11 months ago

Marshalling a non pointer BitSets results in an empty JSON object:

var bs bitset.BitSet
bs.Set(0)
bytes, _ := json.Marshal(bs)
fmt.Println(string(bytes))

To fix this the BitSet.MarshalJSON method needs to be a value receiver instead of a pointer receiver.

lemire commented 11 months ago

This seems to match the documentation: https://pkg.go.dev/encoding/json#RawMessage.MarshalJSON