fix(java): serialize Feign Jackson JSON headers

AN
20h ago
+362-4

Description

Serialize JSON-content header parameters in Java Feign/Jackson clients as JSON instead of the model's toString() value. This extends the behavior addressed for okhttp-gson in #25056 to Feign/Jackson.

The generated client uses its configured Jackson mapper, escapes non-ASCII header characters, and leaves ordinary headers on the existing path. Configure the default mapper to omit optional null properties, consistent with the shared Java client mapper. Update affected Feign samples.

Tests

  • JavaClientCodegenTest#testFeignJacksonJsonHeader.
  • Generated-client runtime tests: ASCII-safe JSON and ordinary headers, and a custom Jackson serializer (2 tests).
  • Generated and compiled the full Dropbox public SDK with --library feign --additional-properties=serializationLibrary=jackson; verified a generated download request's JSON header using a local transport.
  • Regenerated the affected Feign samples twice with an identical diff.

The generated-client runtime fixture was copied into the generated client's test directory and run with Maven.

PR checklist

  • Read the contribution guidelines.
  • Run the full project build, regenerate all samples and export generator docs.
  • Notify the relevant technical committee members.

Summary by cubic

Serializes JSON-content header parameters in generated Java Feign/Jackson clients as JSON instead of the model's toString() value, matching existing okhttp-gson behavior.

  • Adds ApiClient.JsonHeaderParamExpander with a custom Feign contract and array proxy so JSON headers, including arrays, serialize with the client's configured Jackson mapper and escape non-ASCII characters.
  • Applies NON_NULL inclusion only to header serialization; request-body serialization keeps nulls.
  • Enables the expander only for Feign/Jackson clients and resets it between generations; ordinary headers, response-only JSON headers, and other libraries are unaffected.
  • Adds generator and runtime tests covering plain headers, custom serializers, array and empty-array headers, and builder replacement.

Migration
Generated Feign/Jackson clients now output JSON for headers declared with application/json content — callers expecting toString() output must validate their header formats.