spring-projects / spring-projects/spring-ai

DefaultUsage#nativeUsage can crash SimpleLoggingAdvisor

Open
#2,535 0 comments 0 reactions 1 assignee View on GitHub

@sobychacko is already working on this.

Since Sep 5, 2026.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.