Skip to content

fix(java): serialize Feign Jackson JSON headers - #25530

Open
AndreyVMarkelov wants to merge 2 commits into
OpenAPITools:masterfrom
AndreyVMarkelov:andreymarkelov/fix-feign-jackson-json-headers
Open

AndreyVMarkelov wants to merge 2 commits into
OpenAPITools:masterfrom
AndreyVMarkelov:andreymarkelov/fix-feign-jackson-json-headers

Conversation

@AndreyVMarkelov

@AndreyVMarkelov AndreyVMarkelov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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.

Written for commit e66f5fa. 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.

All reported issues were addressed across 9 files

Reply with feedback, questions, or to request a fix.

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.

1 participant