Fix JsonResponseBuilder treating application/vnd.elasticsearch+json as non-JSON#210
Merged
Conversation
…s non-JSON (#210) Both `JsonResponseBuilder` and `DynamicResponseBuilder` gated JSON parsing on `contentType.StartsWith("application/json")`. When Elasticsearch returns `application/vnd.elasticsearch+json` (its default when the client sends a matching `Accept`), the guard failed and the body was wrapped as a raw string under a `body` key instead of being parsed as a `JsonNode`. This caused `val.Get<string>("task")` in `ServerReindex.StartReindexAsync` to return `null` and throw "Reindex response did not contain a 'task' field." Fix: add a virtual `ProductRegistration.IsJsonContentType(string?)` that defaults to `application/json`; `ElasticsearchProductRegistration` overrides it to also accept `application/vnd.elasticsearch+json` (and `;compatible-with=N` variants) while leaving `+x-ndjson` and binary subtypes untouched. Both builders now delegate to `boundConfiguration.ConnectionSettings.ProductRegistration.IsJsonContentType` instead of the hardcoded prefix check. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
flobernd
approved these changes
May 11, 2026
flobernd
left a comment
Member
There was a problem hiding this comment.
LGTM!
Maybe we can also redirect this method
IsJsonContentType.
Eliminates the duplicated application/json + application/vnd.elasticsearch+json check now that IsJsonContentType encapsulates both cases. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
JsonResponseBuilderandDynamicResponseBuilderboth gated JSON parsing oncontentType.StartsWith("application/json"). When Elasticsearch returnsapplication/vnd.elasticsearch+json(its default when the client sends a matchingAcceptheader), that check fails and the body is wrapped as a raw string under{"body": "..."}instead of being parsed as aJsonNode.ServerReindex.StartReindexAsyncinElastic.Ingest.Elasticsearch:val.Get<string>("task")returnednull→ "Reindex response did not contain a 'task' field."Changes
ProductRegistration: new virtualIsJsonContentType(string?)— defaults toapplication/jsonprefix match.ElasticsearchProductRegistration: overrides to also acceptapplication/vnd.elasticsearch+json(and;compatible-with=Nvariants);+x-ndjsonand binary subtypes remain unaffected.JsonResponseBuilder/DynamicResponseBuilder: replace hardcodedStartsWith("application/json")withboundConfiguration.ConnectionSettings.ProductRegistration.IsJsonContentType(contentType).JsonResponseTests: two new theory tests — one confirming vendor JSON types are parsed, one confirming non-JSON vendor types still fall through to raw-string mode.Test plan
BuilderElasticsearchVendorJsonContentType—application/vnd.elasticsearch+json(bare,;compatible-with=8, with space) all parse the JSON body correctlyBuilderElasticsearchVendorNonJsonContentType—+x-ndjsonand+vnd.mapbox-vector-tilestill wrap as raw string underbody🤖 Generated with Claude Code