spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/index.html
Apache License 2.0
2.98k stars 737 forks source link

`chatClient…entity(Foo::class.java)` in Kotlin doesn’t work with Kotlin data classes when it does work in Java records #1345

Open joshlong opened 2 weeks ago

joshlong commented 2 weeks ago

I'm afk but I got an error trying to deserialize a Kotlin data class using the ChatClient's entity(Class<T>) method

mxsl-gr commented 2 weeks ago

try register jackson kotlin module, at least it works for me. essentially kotlin's data class compiles into a class with a full-parameter constructor. register relevant module should resolve the issue

add dependency:

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-kotlin</artifactId>
</dependency>

ObjectMapper register module:

OBJECT_MAPPER.registerModule(new KotlinModule.Builder().build())