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

Wrong google/uuid serialization #259

Open
prochac opened this issue Jan 7, 2021 · 0 comments
Open

Wrong google/uuid serialization #259

prochac opened this issue Jan 7, 2021 · 0 comments

Comments

@prochac
Copy link

prochac commented Jan 7, 2021

ffjson generates wrong marshaler for github/google/uuid#UUID type

It implements fmt.Stringer, encoding.BinaryMarshaler and encoding.TextMarshaler.

Insead of expected

{"Bar":"0eec3f57-eb61-4833-a78e-fdf6eb8ac4ae"}

I get

{"Bar":[14,236,63,87,235,97,72,51,167,142,253,246,235,138,196,174]}

main.go

package ffjson_uuid

import "github.com/google/uuid"

//go:generate ffjson main.go

type Foo struct {
	Bar uuid.UUID
}

main_ffjson.go

...
// MarshalJSONBuf marshal buff to json - template
func (j *Foo) MarshalJSONBuf(buf fflib.EncodingBuffer) error {
	if j == nil {
		buf.WriteString("null")
		return nil
	}
	var err error
	var obj []byte
	_ = obj
	_ = err
	buf.WriteString(`{"Bar":`)
	buf.WriteString(`[`)
	for i, v := range j.Bar {
		if i != 0 {
			buf.WriteString(`,`)
		}
		fflib.FormatBits2(buf, uint64(v), 10, false)
	}
	buf.WriteString(`]`)
	buf.WriteByte('}')
	return nil
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant