Skip to content

Fix BeanOutputConverter List type format mismatch#5795

Open
ehdgusdl wants to merge 2 commits intospring-projects:mainfrom
ehdgusdl:fix/5707-bean-output-converter-mismatch
Open

Fix BeanOutputConverter List type format mismatch#5795
ehdgusdl wants to merge 2 commits intospring-projects:mainfrom
ehdgusdl:fix/5707-bean-output-converter-mismatch

Conversation

@ehdgusdl
Copy link
Copy Markdown

Summary

  • Fix BeanOutputConverter.convert() to handle schema-shaped LLM responses for List types
  • When the target type is a List, some LLMs mirror the JSON schema structure and return {"type":"array","items":[...]} instead of a plain array [...], causing a MismatchedInputException
  • Extract the array from the "items" key when the response matches the schema-shaped pattern

Closes #5707

Changes

BeanOutputConverter.java

  • Added schema-shaped response detection in convert(): when the target type is List and the response is an object with "type":"array" and "items" as an array, extract the array for deserialization
  • Added isListType() helper to check whether the target type is a List or subtype

BeanOutputConverterTest.java

  • convertListTypeFromSchemaShapedResponse: verifies correct extraction from {"type":"array","items":[...]}
  • convertListTypeFromSchemaShapedResponseWithEmptyArray: verifies empty array edge case
  • convertListTypeIgnoresObjectWithItemsField: verifies the fix does not trigger when "type" is not "array"

Test plan

  • New tests pass (31/31)
  • Existing convertTypeReferenceArray test still passes (no regression for normal array responses)
  • Full BeanOutputConverterTest suite passes

김동현 added 2 commits April 13, 2026 03:16
When the target type is a List, some LLMs mirror the JSON schema structure
and return {"type":"array","items":[...]} instead of a plain array [...].
This causes a MismatchedInputException during deserialization.

Extract the array from the "items" key when the response matches the
schema-shaped pattern with "type":"array" and "items" as an array.

Closes spring-projects#5707

Signed-off-by: DHKim7762 <kim138762@gmail.com>
…ndling

- convertListTypeFromSchemaShapedResponse: verify correct extraction
  from {"type":"array","items":[...]} responses
- convertListTypeFromSchemaShapedResponseWithEmptyArray: verify empty
  array edge case
- convertListTypeIgnoresObjectWithItemsField: verify the fix does not
  trigger when "type" is not "array"

Signed-off-by: DHKim7762 <kim138762@gmail.com>
@ehdgusdl ehdgusdl force-pushed the fix/5707-bean-output-converter-mismatch branch from 350bf21 to 6102312 Compare April 12, 2026 18:17
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.

BeanOutputConverter getFormat() and convert() format mismatch for List types

1 participant