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

Marshalling fails with Interface members when they are nil #13

Closed
joeblubaugh opened this issue Dec 6, 2019 · 1 comment · Fixed by #14
Closed

Marshalling fails with Interface members when they are nil #13

joeblubaugh opened this issue Dec 6, 2019 · 1 comment · Fixed by #14
Assignees
Labels
bug Something isn't working

Comments

@joeblubaugh
Copy link

I was migrating some marshalling code to use this library over the standard library (thank you for making it!) and encountered this error. Note that the stdlib reports a nil error with data, while segmentio/encoding/json returns an error. i

Minimal repro:

package main

import (
	"fmt"

	"github.com/segmentio/encoding/json"
)

type segmentJSON struct {
	Stringer fmt.Stringer
	Field    int `json:"MyInt"`
}

func main() {
	fmt.Println("segment-error")
	js := segmentJSON{Field: 2}
	fmt.Println(json.Marshal(js))
}

Output when using encoding/json:

❯ go run main.go
segment-error
[123 34 83 116 114 105 110 103 101 114 34 58 110 117 108 108 44 34 77 121 73 110 116 34 58 50 125] <nil>

with github.com/segmentio/encoding/json:

❯ go run main.go
segment-error
[] json: unsupported type: fmt.Stringer
@achille-roussel
Copy link
Contributor

@joeblubaugh thanks for reporting it the issue, looking into it.

@pelletier pelletier added the bug Something isn't working label Dec 6, 2019
@pelletier pelletier changed the title Bug: Marshalling Fails with Interface members when they are nil Marshalling fails with Interface members when they are nil Dec 6, 2019
@achille-roussel achille-roussel self-assigned this Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants