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

Allow Custom types in java JsonFormat utility #8162

Closed
Gaff opened this issue Dec 23, 2020 · 1 comment
Closed

Allow Custom types in java JsonFormat utility #8162

Gaff opened this issue Dec 23, 2020 · 1 comment

Comments

@Gaff
Copy link

Gaff commented Dec 23, 2020

We have a problem where we want to represent a date as an ISO format string in JSON, but we wish to use google.type.Date in protobuf. I'm using the JsonFormat tool to build the protobuf from the JSON, but this fails since it sees a string in the JSON but the mergeMessage method expects it to be a JsonObject.

So would you consider a change where people can register custom parsers, so that users can extend the JsonFormat to support any types?

My proposal would involve the following steps:
1, Expose WellKnownTypeParser as a public interface.
2. Make wellKnownTypePrasers in ParserImpl non-static, add constructor params.
3. Add a usingTypeParser() method to Parser

And analogous steps for Printer.

Would this be viable?

@elharo
Copy link
Contributor

elharo commented Sep 30, 2021

My gut is that this won't fly. JsonFormat is designed to supprot a single consistent and reproducible JSON format for protos across languages, not as a general purpose converter between arbitrary JSON formats and protos. I don't think we want to add complexity to the API to support this. However this could be a viable third party library.

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

2 participants