Skip to content

fix(java): serialize primitive arrays in Gson oneOf - #25542

Open
AndreyVMarkelov wants to merge 1 commit into
OpenAPITools:masterfrom
AndreyVMarkelov:andreymarkelov/fix-java-gson-oneof-array
Open

AndreyVMarkelov wants to merge 1 commit into
OpenAPITools:masterfrom
AndreyVMarkelov:andreymarkelov/fix-java-gson-oneof-array

Conversation

@AndreyVMarkelov

@AndreyVMarkelov AndreyVMarkelov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #25541

Fix Java okhttp-gson serialization of a oneOf containing an array of primitive strings. The generated adapter now writes the array as a JsonArray instead of trying to convert it to a JsonPrimitive.

This reproduces on master independently of #25539. Empty array values have a separate existing limitation in setActualInstance and are outside this change.

Tests

  • Added a focused generator test that compiles and exercises the generated Gson adapter with a nonempty string array and an object. The array case failed before the fix.
  • Generated a complete client from the reproduction schema; it compiled and round-tripped the string array and object.
  • Ran the existing Java okhttp-gson-oneOf-array sample tests: 3 passed, 1 skipped.
  • Regenerated the affected Java okhttp-gson samples.

Summary by cubic

Fixes #25541: Java okhttp-gson generation previously serialized a oneOf containing a primitive string array by calling getAsJsonPrimitive() on the array's JSON tree, which threw an exception. The generated adapter now writes the array as a JsonArray, so the schema round-trips correctly.

  • Updates the oneof_model.mustache template to handle array types separately from other primitives.
  • Adds a generator test that compiles the adapter and verifies round-tripping a string array and an object, plus the corresponding test spec.
  • Regenerates the affected okhttp-gson samples.
  • Empty array values still hit an existing separate limitation in setActualInstance and are not addressed here.

Written for commit c5cb902. Summary will update on new commits.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 6 files

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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][Java][okhttp-gson] Cannot serialize oneOf array of strings

1 participant