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

Problem with JSON #873

Closed
yossigi opened this issue Dec 14, 2018 · 1 comment
Closed

Problem with JSON #873

yossigi opened this issue Dec 14, 2018 · 1 comment
Assignees
Labels

Comments

@yossigi
Copy link

yossigi commented Dec 14, 2018

The test below illustrates the problem.
A struct containing a logrus.Level member encodes with JSON,
but decoding results in an error.
(Removing Level's UnmarshalText function seems to solve this issue, though it might be undesirable)

func TestJson(t *testing.T) {
       type X struct {
               Level logrus.Level
       }

       var x X
       x.Level = logrus.WarnLevel
       var buf bytes.Buffer
       enc := json.NewEncoder(&buf)
       assert.NoError(t, enc.Encode(x))
       dec := json.NewDecoder(&buf)
       var y X
       assert.NoError(t, dec.Decode(&y))
}

@dgsb
Copy link
Collaborator

dgsb commented Dec 26, 2018

We could also implements the TextMarshaller interface to have the encoding and decoding functions.

@dgsb dgsb self-assigned this Dec 26, 2018
@dgsb dgsb added the bug label Dec 26, 2018
dgsb added a commit that referenced this issue Dec 26, 2018
Since the implementation of the TextMarshaller interface
we could not unmarshal previously json marshalled Level value.
Fixes #873
@dgsb dgsb closed this as completed in #878 Dec 26, 2018
cgxxv pushed a commit to cgxxv/logrus that referenced this issue Mar 25, 2022
Since the implementation of the TextMarshaller interface
we could not unmarshal previously json marshalled Level value.
Fixes sirupsen#873
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