Skip to content

Wrong google/uuid serialization #259

Description

@prochac

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions