Skip to content

jsonpb should support custom JSON serialization #331

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

Closed
jhump opened this issue Apr 3, 2017 · 8 comments
Closed

jsonpb should support custom JSON serialization #331

jhump opened this issue Apr 3, 2017 · 8 comments

Comments

@jhump
Copy link
Contributor

jhump commented Apr 3, 2017

This would be done by delegating to the message if it implements json.Marshaler or json.Unmarshaler.

FWIW, this could simplify how the well-known types are handled, e.g. no need to special-case them in this package. (So, in a way, this issue relates to #169.)

Both the binary and text encodings already support the same concept, where a message can implement a particular interface (proto.Marshaler/proto.Unmarshaler, encoding.TextMarshaler/encoding.TextUnmarshaler) to customize serialization/de-serialization. This just extends that same concept to JSON encoding/decoding.

I've also opened a pull request that implements the change: #325

I think consistency with binary and text marshaling is a reasonable justification for the change. But I also have my own reason for the change: allow users of a dynamic message library to use jsonpb as they would with any other proto.Message.

@jhump
Copy link
Contributor Author

jhump commented Apr 8, 2017

ping

@jhump
Copy link
Contributor Author

jhump commented Apr 19, 2017

@bcmills, pinging you since git blame identifies you as the last to touch the jsonpb package. Mind giving this a brief glance?

@bcmills
Copy link
Contributor

bcmills commented Apr 19, 2017

"Last to touch the package" isn't a great heuristic. I think @dsnet, @cherrymui, and @randall77 have been working on proto stuff lately.

@jhump
Copy link
Contributor Author

jhump commented Apr 19, 2017

"Last to touch the package" isn't a great heuristic.

Agreed, it isn't. But outsiders have pretty poor visibility into anything better, and I was hoping to get some feedback on this vs. letting it languish like so many other issues and pull requests.

Thanks for tagging the relevant folks!

@dsnet
Copy link
Member

dsnet commented Apr 19, 2017

\cc @cybrcodr, who will be handling some of the jsonpb-related PRs and issues.

@jhump
Copy link
Contributor Author

jhump commented May 8, 2017

@cybrcodr: ping

@dsnet dsnet added the jsonpb label May 18, 2017
@cybrcodr
Copy link
Contributor

I think this sounds reasonable for dynamic messages. But it would be better for WKT's JSON (de)serialization be as implemented right now. I'll review your PR soon.

@dsnet
Copy link
Member

dsnet commented May 22, 2017

Fixed in #325

@dsnet dsnet closed this as completed May 22, 2017
@golang golang locked as resolved and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants