Skip to content

fix(codegen): deserialize typed JSON responses instead of casting JsonDocument#31

Merged
matoous merged 1 commit intomainfrom
md/fix-list-parsing
Feb 19, 2026
Merged

fix(codegen): deserialize typed JSON responses instead of casting JsonDocument#31
matoous merged 1 commit intomainfrom
md/fix-list-parsing

Conversation

@matoous
Copy link
Contributor

@matoous matoous commented Feb 19, 2026

Issue #30 reported InvalidCastException in ReadersClient.List/ListAsync. The generated SDK code parsed response content as JsonDocument and cast it to ReadersListResponse, which fails at runtime.

Root cause:

  • response mode selection re-inferred type from raw response schema
  • for some inline/object responses it chose "json-document"
  • generated clients emitted (T)(object)document casts for typed responses

Fix:

  • change response mode resolution to use the already resolved response type from resolveResponseType(...)
  • keep "json-document" mode only when ResponseType is JsonDocument
  • use normal JSON deserialization for typed responses

Added regression test.

Fixes: #30

…nDocument

Issue #30 reported `InvalidCastException` in
`ReadersClient.List/ListAsync`. The generated SDK code parsed response
content as `JsonDocument` and cast it to `ReadersListResponse`,
which fails at runtime.

Root cause:
- response mode selection re-inferred type from raw response schema
- for some inline/object responses it chose "json-document"
- generated clients emitted `(T)(object)document` casts for typed
  responses

Fix:
- change response mode resolution to use the already resolved response
  type from resolveResponseType(...)
- keep "json-document" mode only when `ResponseType` is `JsonDocument`
- use normal JSON deserialization for typed responses

Added regression test.

Fixes: #30
@matoous matoous self-assigned this Feb 19, 2026
@matoous matoous merged commit 29cdd9e into main Feb 19, 2026
7 checks passed
This was referenced Feb 19, 2026
@matoous matoous deleted the md/fix-list-parsing branch February 19, 2026 08:30
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.

client.Readers.List() fails with System.InvalidCastException

1 participant