-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(grpc-transcode): correctly serialize empty repeated fields to [] #12391
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
Conversation
Co-authored-by: Traky Deng <[email protected]>
…tion of each phase (apache#11793)
Co-authored-by: Ashish Tiwari <[email protected]>
Signed-off-by: xuruidong <[email protected]>
…t. (apache#11783) Co-authored-by: root <[email protected]>
* docs: improve real-ip plugin docs * update Chinese version * fix comments & lint * Update real-ip.md * Update real-ip.md * add notes back * fix typo
Hi @bytelazy, could you please merge the latest master branch code? |
sure, I have merged the latest master branch |
Hi @bytelazy, some failed tests need to be fixed. |
Got it. I'll fix the failed tests soon. |
11e3559
to
a0356cd
Compare
hi @Baoyuantop Sorry for the inconvenience, and please continue the review there 🙏 |
Description
In the grpc-transcode plugin, when a repeated field in the gRPC response is empty, it is incorrectly encoded as an empty JSON object ({}) instead of an empty JSON array ([]). This behavior does not comply with the gRPC-JSON transcoding specification and can cause type-related errors on the client-side, which expects an array.
Fixes #11440
Checklist
Changes or the new features added to this PR
The main changes are in the response.lua file to correctly handle the serialization of repeated fields.
Identify repeated fields: A new function fetch_proto_array_names has been added. It recursively traverses the loaded Protobuf schema definition to identify and collect the names of all fields marked as repeated.
Ensure correct JSON array serialization:
A new function set_default_array has been introduced. After the gRPC response is decoded into a Lua table, this function traverses the table.
For any field that was identified as repeated, it sets a specific metatable (core.json.array_mt).
This metatable forces the core.json.encode function to serialize the corresponding Lua table as a JSON array ([]), even when it is empty.
This logic is applied just before the decoded response is encoded into the final JSON output, ensuring the structure is correct.