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

easyjson doesn't respect TextUnmarshaler #28

Open
i opened this issue May 20, 2016 · 0 comments
Open

easyjson doesn't respect TextUnmarshaler #28

i opened this issue May 20, 2016 · 0 comments

Comments

@i
Copy link

i commented May 20, 2016

https://golang.org/src/encoding/encoding.go?s=1851:1919#L36

For example, the following code will not work as expected with easyjson:

package main

import (
    "encoding/json"
    "fmt"
)

type Number int64

func (n *Number) UnmarshalText(text []byte) error {
    switch string(text) {
    case "ONE":
        *n = 1
    case "TWO":
        *n = 2
    default:
        *n = -1
    }
    return nil
}

type S struct {
    Index Number
}

func main() {
    var s S
    json.Unmarshal([]byte(`{"index": "ONE"}`), &s)
    fmt.Println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants