Handling of Null or Empty Fields in JSON Serialization for gRPC Responses #1463
Labels
bug
Categorizes issue or PR as related to a bug.
feature
Categorizes issue or PR as related to a new feature.
good first issue
Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.
Milestone
Problem Description
In our current implementation using protocol buffers with gRPC in Go, we've encountered an issue where JSON serialization omits fields with null or empty values due to the
omitempty
option. This behavior is not always desirable, especially when the client expects all fields, regardless of whether they hold a value or not.Impact
This behavior can lead to inconsistent API responses and potential misunderstandings on the client side, as the client might expect all defined fields to be present in the response.
Possible Solution
We are looking for a solution that allows us to include all defined fields in the JSON response, even if their value is null or empty, without modifying the default behavior set by the
omitempty
option in the protocol buffer compiler for Go.Considerations
References
We've noted that similar issues have been discussed in the context of the Go-Kratos framework (e.g., go-kratos/kratos#1539 and go-kratos/kratos#1952). We're looking for advice or solutions that may have been identified in these or other discussions.
Request
We kindly request guidance on how to approach this serialization concern while adhering to the gRPC and protocol buffer standards in Go. Any suggestions or recommendations for practices or tools to resolve this issue would be greatly appreciated.
The text was updated successfully, but these errors were encountered: