You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe to have discovered an inconsistency in behavior between json-iterator and stdlib's encoding/json package.
Specifically, if you try to marshal a pointer to a struct which contains a function field, json-iterator returns an error from Marshal whereas the same method on encoding/json does not. To better illustrate, I have put together an example repository where the main.go file looks like this:
$ go run main.go
json-iterator: marshalling failed: [optional]: [main.str]: unsupported type: func()
encoding/json: marshalling succeeded.
Note that adding tags to ignore the function field might work in this artificial example but not in the general case. In fact, I ran into this issue while trying to marshal a struct holding a pointer to a tls.Config struct. This struct holds a Time func() time.Time field and produces the following error message during Marshal:
[tls.Config]: unsupported type: func() time.Time
Obviously, I cannot add tags to a struct embedded in the stdlib.
The text was updated successfully, but these errors were encountered:
I believe to have discovered an inconsistency in behavior between json-iterator and stdlib's encoding/json package.
Specifically, if you try to marshal a pointer to a struct which contains a function field, json-iterator returns an error from
Marshal
whereas the same method on encoding/json does not. To better illustrate, I have put together an example repository where themain.go
file looks like this:Executing the application, the output is:
Note that adding tags to ignore the function field might work in this artificial example but not in the general case. In fact, I ran into this issue while trying to marshal a struct holding a pointer to a
tls.Config
struct. This struct holds aTime func() time.Time
field and produces the following error message duringMarshal
:Obviously, I cannot add tags to a struct embedded in the stdlib.
The text was updated successfully, but these errors were encountered: