Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

struct encoding and whitespace #23

Open
benjiqq opened this issue May 8, 2020 · 1 comment
Open

struct encoding and whitespace #23

benjiqq opened this issue May 8, 2020 · 1 comment
Labels

Comments

@benjiqq
Copy link

benjiqq commented May 8, 2020

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)) 
	}
}
@benjiqq benjiqq changed the title map encoding and whitespace struct encoding and whitespace May 8, 2020
@hypirion
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants