protobuf
protobuf copied to clipboard
[java] Add config option to print 64-bit integers in JSON as unquoted ints if they can be losslessly converted into a 64-bit float
The title of this issue is taken from the following commit made in March 2023. https://github.com/protocolbuffers/protobuf/commit/330e10d53fe1c12757f1cdd7293d0881eac4d01e
That commit added a configuration option to the C++ JSON printer for printing 64-bit integers in JSON as unquoted ints if they can be losslessly converted into a 64-bit float. This issue is a request for a similar configuration option to be added to the Java JSON printer.
What language does this apply to? This applies to the JSON printing functionality in the util libraries. I am primarily concerned with Java.
Describe the problem you are trying to solve. I have a need to export protobuf integers in the range of (2^32, 2^53) as JSON numbers instead of as decimal strings. I want to be able to do this without sacrificing the benefits of using an integer type in my protobuf definitions.
Describe the solution you'd like The solution in the linked commit seems great to me and its functionality already in the protobuf codebase. Similar functionality in Java and other languages seems most appropriate.
Describe alternatives you've considered Other solutions are talked about in the linked issues below. None of them resulted in an implementation.
Additional context
Something like this has been in high demand from the community for a while. Some previous issues around this topic:
- https://github.com/protocolbuffers/protobuf/issues/1823
- https://github.com/protocolbuffers/protobuf/issues/2679
- https://github.com/golang/protobuf/issues/1414
- https://github.com/protocolbuffers/protobuf/issues/3194
- https://github.com/protocolbuffers/protobuf/issues/3423
- https://github.com/protocolbuffers/protobuf/issues/2954
- https://github.com/protocolbuffers/protobuf/issues/4103
- https://github.com/protocolbuffers/protobuf/issues/5942