fix(java): serialize primitive arrays in Gson oneOf

AN
19h ago
+114-6

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.