edn
edn copied to clipboard
struct encoding and whitespace
was decoding a struct and the resulting map does not have whitespace between the keyword and value and between the next value?
in this case I was expecting {:name \"Hans\" :born 1990}
func TestMapEncoding(t *testing.T) {
type Person struct {
Name string `edn:"name"`
Birthyear int `edn:"born"`
}
user := Person{Name: "Hans", Birthyear: 1990}
dat, _ := Marshal(user)
if string(dat) != "{:name \"Hans\" :born 1990}" {
t.Error("fails", string(dat))
}
}
@benjyz: I'm a bit late to this one, but go-edn's Marshal only writes whitespace when it needs to. " is only allowed at the start and end of strings (except when quoted inside strings), which means there's no reason to add a whitespace there.
Note that Marshal is not designed to create output read by humans. If you want human-readable output, you may want to look into edn.MarshallIndent or edn.MarshallPPrint, which both write out data in a more approachable manner for humans.