Skip to content

#2497 fix: resolve JSON serialization issue with empty Object[] arrays#2550

Merged
robfrank merged 9 commits intomainfrom
fix/2497-json-empty-array-serialization
Sep 23, 2025
Merged

#2497 fix: resolve JSON serialization issue with empty Object[] arrays#2550
robfrank merged 9 commits intomainfrom
fix/2497-json-empty-array-serialization

Conversation

@robfrank
Copy link
Collaborator

This pull request addresses a serialization bug with empty arrays in JSON handling, specifically fixing a NoSuchElementException when serializing documents containing empty arrays (issue #2497). The changes ensure that empty arrays and Object[] types are properly handled and serialized as JSON arrays, not as Java object string representations. The update also adds comprehensive tests to verify correct behavior for empty and non-empty arrays in various scenarios.

Bug fix: JSON serialization of empty arrays and Object[]

  • Updated JsonSerializer.java and JSONObject.java to correctly handle and serialize empty arrays and Object[] types as JSON arrays, preventing exceptions and incorrect string representations. [1] [2] [3]

Testing: Verification of serialization and SQL handling

  • Added JSONEmptyArraySerializationTest.java to thoroughly test JSON serialization and deserialization of empty arrays, empty collections, and nested arrays, ensuring robust handling and correct output.
  • Added JSONObjectArrayFixTest.java to specifically verify that Object[] arrays, including empty and mixed content, serialize and deserialize correctly as JSON arrays.
  • Added InsertContentEmptyArrayTest.java to reproduce and verify the fix for SQL INSERT CONTENT statements with empty arrays, ensuring no exceptions are thrown and correct data retrieval.

@robfrank robfrank added this to the 25.9.1 milestone Sep 23, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @robfrank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the JSON serialization logic where empty arrays and Object[] types were not handled correctly, leading to exceptions or incorrect output. The changes modify the serialization process to ensure these data structures are always represented as valid JSON arrays, significantly improving the robustness and reliability of JSON data handling within the system, particularly for database operations like INSERT CONTENT.

Highlights

  • JSON Serialization Fix: Resolved a NoSuchElementException that occurred when serializing documents containing empty arrays, ensuring they are correctly represented as JSON arrays.
  • Object[] Handling: Ensured that Object[] types, including empty ones, are properly serialized as JSON arrays instead of their Java object string representations.
  • Comprehensive Testing: Added new test suites (JSONEmptyArraySerializationTest, JSONObjectArrayFixTest, InsertContentEmptyArrayTest) to thoroughly verify correct serialization of empty arrays, collections, and Object[] in various scenarios, including SQL INSERT CONTENT statements.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@robfrank robfrank linked an issue Sep 23, 2025 that may be closed by this pull request
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the JSON serialization issue with empty arrays, particularly the NoSuchElementException and incorrect serialization of Object[] types. The changes in JsonSerializer.java and JSONObject.java are correct and well-targeted. The inclusion of three new, comprehensive test files (InsertContentEmptyArrayTest.java, JSONEmptyArraySerializationTest.java, and JSONObjectArrayFixTest.java) is excellent, ensuring the fix is robust and preventing future regressions. I have provided a few suggestions to enhance the new test code for better consistency and readability.

robfrank and others added 7 commits September 23, 2025 00:02
…tentEmptyArrayTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…tentEmptyArrayTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…tentEmptyArrayTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…aySerializationTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…rayFixTest.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@codacy-production
Copy link

codacy-production bot commented Sep 23, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.01% 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (d76c6f9) 72462 45649 63.00%
Head commit (90bc7a5) 72464 (+2) 45661 (+12) 63.01% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2550) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@robfrank robfrank merged commit 5472588 into main Sep 23, 2025
15 of 19 checks passed
robfrank added a commit that referenced this pull request Nov 10, 2025
@robfrank robfrank deleted the fix/2497-json-empty-array-serialization branch January 14, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Insert fails with JSON content containing empty array

1 participant