feat(ktor-server): skip internal ContentNegotiation install when already configured#2174
Merged
samuelAndalon merged 2 commits intoMay 18, 2026
Conversation
…ady configured When the host application has already installed ContentNegotiation at the application level — a common pattern when the app serves other JSON endpoints or uses StatusPages with JSON error responses — the existing unconditional route-scoped install in graphQLGetRoute and graphQLPostRoute caused Ktor to throw DuplicatePluginException. The install is now guarded by application.pluginOrNull(ContentNegotiation): if the plugin is present at the application level, the route-scoped install is skipped and the existing configuration is reused. When no global install exists, behaviour is unchanged. Added regression tests for both route helpers. Fixes ExpediaGroup#2025
samuelAndalon
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Route.graphQLGetRoute()andRoute.graphQLPostRoute()unconditionally installContentNegotiationon the route scope. When the host application has already installedContentNegotiationat the application level — a common pattern when the app serves other JSON endpoints or usesStatusPageswith JSON error responses — Ktor throwsDuplicatePluginException:This PR makes the internal install conditional on
application.pluginOrNull(ContentNegotiation):ContentNegotiationis already installed at the application level, the route-scoped install is skipped and the existing global configuration is reused.streamingResponseandjacksonConfiguration.When the global install wins,
streamingResponseandjacksonConfigurationare not applied, since the application-level configuration takes precedence; this trade-off is documented in the KDoc for both routes.No API change; fully backward compatible.
Added two regression tests in
GraphQLPluginTestcovering the globally-installed case for both the GET and POST routes.🔗 Related Issues
Fixes #2025