Skip to content
This repository was archived by the owner on Dec 4, 2019. It is now read-only.

Support json.Marshaler and json.Unmarshaler - #16

Open
tejasmanohar wants to merge 2 commits into
masterfrom
std_json_interfaces
Open

tejasmanohar wants to merge 2 commits into
masterfrom
std_json_interfaces

Conversation

@tejasmanohar

Copy link
Copy Markdown

Solves #12

@achille-roussel achille-roussel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but I'm not sure if this is the right way to solve the problem.
The main issue I'm seeing is that this doesn't produce the same representation than using the standard encoding/json package, for example for this type:

import "github.com/google/uuid"

type A struct {
  ID uuid.UUID // implements json.Marshaler
}
import "encoding/json"
...
u, _ := uuid.Parse("6E78219C-8FD0-49CC-AA29-2B8D87E6D64D")
b, _ := json.Marshal(A{ID: u})
// {"ID":"6E78219C-8FD0-49CC-AA29-2B8D87E6D64D"}
import "github.com/segmentio/objconv/json"
...
u, _ := uuid.Parse("6E78219C-8FD0-49CC-AA29-2B8D87E6D64D")
b, _ := json.Marshal(A{ID: u})
// {"ID":"\"6E78219C-8FD0-49CC-AA29-2B8D87E6D64D\""}

This is a bug that would be pretty hard to track down, I feel like the right thing to do would be to match the behavior of the standard library.

What do you think?

@achille-roussel

Copy link
Copy Markdown
Contributor

@tejasmanohar any updates on this?

@tejasmanohar

Copy link
Copy Markdown
Author

Sorry, missed this! That doesn't look good... I intended to match behavior of the standard library. Does the problem apply to other standard library encodings in objconv, too (e.g. encoding.TextMarshaler)? I'll have time to investigate later this week.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants