Skip to content

Make BeanOutputConverter more extensible #2788

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markpollack
Copy link
Member

Summary

  • Makes BeanOutputConverter class more subclass-friendly by changing access modifiers for key fields and methods
  • Extracts template string in getFormat() to allow customization by subclasses
  • Provides better extension points for customizing behavior

Fixes #1985

@markpollack markpollack force-pushed the 1985-bean-output-converter branch from 825f14a to 34d5f9c Compare April 17, 2025 19:47
This change improves the extensibility of BeanOutputConverter by:
- Making generateSchema method and jsonSchema field protected
- Making logger and type fields protected for subclass access
- Extracting format template into a separate protected method

These changes allow subclasses to access and override key parts
of the converter's behavior without having to reimplement large
portions of the class.

Fixes #1985

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
@ThomasVitale
Copy link
Contributor

ThomasVitale commented Apr 26, 2025

@markpollack since BeanOutputConverter implements StructuredOutputConverter, would it be enough to create a custom StructuredOutputConverter implementation if a different logic is desired?

I can already define a MyBeanOutputConverter which implements StructuredOutputConverter and define my custom logic for the schema generation. Actually, that's what I do in my projects. I implemented my own version, and re-used the JsonSchemaGenerator class for generating the schema, which is the same logic used for tool calling. I didn't experience limitations in terms of extensibility.

I'm afraid that by opening up methods and fields in BeanOutputConverter, it will be more difficult to evolve the structured output support due to backward compatibility. We had a similar issue in the old FunctionCallback implementations, which exposed methods to customise schemas and ObjectMapper, and that made it difficult to change the internal implementation since all the internal methods were protected, leaking internal implementation details and preventing from changing the implementation. In that case, we solved it by introducing a different API (ToolCallback), but here it would be more challenging.

I would tend to suggest evolving BeanOutputConverter to be a final class. Customizations would still be possible either via a delegate pattern or by introducing a custom implementation.

What do you think?

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for BeanOutputConverter with non-standard enum mapping
2 participants