spring-projects / spring-projects/spring-ai
DefaultUsage#nativeUsage can crash SimpleLoggingAdvisor
@sobychacko is already working on this.
Since Sep 5, 2026.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
The nativeUsage object within DefaultUsage may not be JSON serialisable and hence causes a crash when using SimpleLoggingAdvisor.
I've hit this when using VertexAI, where the nativeUsage instance, which is cast as an Object, is a protobuf of type GenerateContentRepsonse$UsageMetadata.
This can't be serialised for pretty printing within the SimpleLoggerAdvisor repsonse code, which calls ModelOptionsUtils#toJsonStringPrettyPrinter and thus throws an Exception.
public static String toJsonStringPrettyPrinter(Object object) {
try {
return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(object);
}
catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
I think simplest solution would be to add a @JsonIgnore to DefaultUsage#getNativeUsage as it's not always obvious if it can be logged.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.