Class ConfigMapper

java.lang.Object
com.google.adk.models.springai.ConfigMapper

public class ConfigMapper extends Object
Maps between ADK GenerateContentConfig and Spring AI ChatOptions in both directions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.ai.chat.prompt.ChatOptions
    Creates default ChatOptions for cases where no ADK config is provided.
    boolean
    isChatOptionsValid(@Nullable org.springframework.ai.chat.prompt.ChatOptions chatOptions)
    Validates that Spring AI ChatOptions values fall within valid ADK generation bounds.
    boolean
    isConfigurationValid(Optional<com.google.genai.types.GenerateContentConfig> config)
    Validates that the configuration is compatible with Spring AI.
    @Nullable com.google.genai.types.GenerateContentConfig
    toGenerateContentConfig(@Nullable org.springframework.ai.chat.prompt.ChatOptions chatOptions)
    Converts Spring AI ChatOptions to an ADK GenerateContentConfig.
    @Nullable org.springframework.ai.chat.prompt.ChatOptions
    toSpringAiChatOptions(Optional<com.google.genai.types.GenerateContentConfig> config)
    Converts ADK GenerateContentConfig to Spring AI ChatOptions.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConfigMapper

      public ConfigMapper()
  • Method Details

    • toSpringAiChatOptions

      public @Nullable org.springframework.ai.chat.prompt.ChatOptions toSpringAiChatOptions(Optional<com.google.genai.types.GenerateContentConfig> config)
      Converts ADK GenerateContentConfig to Spring AI ChatOptions.

      When GenerateContentConfig.responseJsonSchema() or GenerateContentConfig.responseSchema() is present, the returned options implement StructuredOutputChatOptions carrying the serialized JSON schema.

      Parameters:
      config - The ADK configuration to convert
      Returns:
      Spring AI ChatOptions or null if no config provided
    • toGenerateContentConfig

      public @Nullable com.google.genai.types.GenerateContentConfig toGenerateContentConfig(@Nullable org.springframework.ai.chat.prompt.ChatOptions chatOptions)
      Converts Spring AI ChatOptions to an ADK GenerateContentConfig.

      When chatOptions implements StructuredOutputChatOptions with a non-blank output schema, the parsed schema is set as GenerateContentConfig.responseJsonSchema() with a JSON response MIME type.

      Parameters:
      chatOptions - The Spring AI chat options to convert, or null
      Returns:
      ADK GenerateContentConfig, or null if chatOptions is null
    • createDefaultChatOptions

      public org.springframework.ai.chat.prompt.ChatOptions createDefaultChatOptions()
      Creates default ChatOptions for cases where no ADK config is provided.
      Returns:
      Basic ChatOptions with reasonable defaults
    • isConfigurationValid

      public boolean isConfigurationValid(Optional<com.google.genai.types.GenerateContentConfig> config)
      Validates that the configuration is compatible with Spring AI.
      Parameters:
      config - The ADK configuration to validate
      Returns:
      true if configuration is valid and supported
    • isChatOptionsValid

      public boolean isChatOptionsValid(@Nullable org.springframework.ai.chat.prompt.ChatOptions chatOptions)
      Validates that Spring AI ChatOptions values fall within valid ADK generation bounds.
      Parameters:
      chatOptions - The Spring AI chat options to validate, or null
      Returns:
      true if the options are valid