Skip to content

fix(client): handle JsonValue input in toParam conversion#351

Draft
packyg wants to merge 1 commit into
release-please--branches--main--changes--nextfrom
packy/fix-toparam-jsonvalue
Draft

fix(client): handle JsonValue input in toParam conversion#351
packyg wants to merge 1 commit into
release-please--branches--main--changes--nextfrom
packy/fix-toparam-jsonvalue

Conversation

@packyg

@packyg packyg commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Stainless commit e3b5adb ("fix(client): bad toParam conversion", part of #350) generated toParam() code that does:

.input(
    _input().map {
        ToolUseBlockParam.Input.builder()
            .additionalProperties(it._additionalProperties())
            .build()
    }
)

This fails to compile because _input() returns JsonValue (which is JsonField<Nothing>), so inside .map { it -> ... } the lambda parameter it infers as Nothing and it._additionalProperties() is unresolved.

Fix

Revert these call sites to .input(_input()). This compiles because JsonField<out T> is covariant and the param builder accepts JsonField<Input>, so JsonValue (= JsonField<Nothing>) is a valid argument. The free-form JSON input passes through unchanged, which is the desired behavior for toParam() round-tripping.

Files changed

  • anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/ToolUseBlock.kt
  • anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/ServerToolUseBlock.kt
  • anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlock.kt
  • anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlock.kt
  • anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolUseBlock.kt

Notes

This is a manual patch over Stainless-generated code; it will be overwritten the next time Stainless regenerates these files unless the codegen is fixed upstream to special-case JsonValue-typed source fields in toParam() conversions.

Verified locally with ./gradlew :anthropic-java-core:compileKotlin (BUILD SUCCESSFUL).

Context: #350

Stainless commit e3b5adb generated toParam() code that calls
it._additionalProperties() inside _input().map{}, but _input()
returns JsonValue (JsonField<Nothing>) so `it` is Nothing.
Manual patch until Stainless codegen handles this case.
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