Closed mithmatt closed 6 years ago
Hi @mithmatt. Thank you for raising the issue. This is because map keys are handled differently when they are marshaled to JSON. As per the documentation (https://golang.org/pkg/encoding/json/#Marshal)
Map values encode as JSON objects. The map's key type must either be a string, an integer type, or implement encoding.TextMarshaler. The map keys are sorted and used as JSON object keys by applying the following rules, subject to the UTF-8 coercion described for string values above:
- string keys are used directly
- encoding.TextMarshalers are marshaled
- integer keys are converted to strings
So in order for map keys to work properly, the type must implement the encoding.TextMarshaler
interface. I'll add this feature under the new flag name text
Done! @mithmatt check the latest changes. You need to include the new flag text
(besides json
) and your map keys will be properly encoded ;-)
@alvaroloes Thanks. I see the new commit that you added.
Eg (pseudocode):
enums/myenum.go
:main.go
:The above code will print the output:
Expected output: