Skip to content

Conversation

@worldtiki
Copy link

Summary

Introduces Spring Boot auto-configuration for customizable Jackson ObjectMapper instances used throughout Spring AI, addressing JSON parsing issues with LLM-generated content.

Key Changes

  • Added new spring-ai-autoconfigure-json-parser module with auto-configuration
  • Provides two specialised ObjectMapper beans:
    • jsonParserObjectMapper - Lenient parsing for LLM responses
    • modelOptionsObjectMapper - Configurable parsing for model options

Configuration

New properties available under spring.ai.json.*:

  • Control unescaped characters, date formats, empty string handling
  • Configure unknown property and empty bean behavior
  • Handle enum coercion for API compatibility

I believe this fixes #2494

Signed-off-by: Daniel Albuquerque <[email protected]>
@ericbottard
Copy link
Member

Hi @worldtiki,

thanks for your contribution!

While I can appreciate the need to provide means to customize ObjectMappers used in Spring AI, this PR seems too "overengineered" to me. IMO, there is no need for a dedicated maven module and autoconfiguration class for this. A change to existing configuration should hopefully suffice, keeping the approach of naming the OM beans.

Moreover, introducing ConfigurationProperties to drive the configuration of the OM is overkill. It merely reproduces what Jackson already provides and limits the configuration to what you've provided here. Just let users define their own OM bean if they want to, leveraging every Jackson feature they want if needed.

Lastly, I shall mention that complexifying the Jackson story in Spring AI before we migrate to Spring 7 / Boot 4 (which uses Jackson 3) may not be the best timing, so we should be very careful to not make things more complicated than they need be.

@worldtiki
Copy link
Author

Yeap that's fair @ericbottard.
Let me take a second look and try to simplify this.

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.

JsonParser is using a self instantiated ObjectMapper, allow usage of a custom ObjectMapper instance

2 participants