I've provided a Spring Boot app that reproduces a bug with serializing UUIDs in Spring Boot v4.0.0-M3 (be sure to use the jackson-issue-v4.0.0-M3 branch).

There are two tests in the app

  1. createItemWithNotNullId - fails
  2. createItemWithNullId - passes

The failure stacktrace is below

java.lang.NullPointerException: Cannot invoke "tools.jackson.core.util.JacksonFeatureSet.isEnabled(tools.jackson.core.util.JacksonFeature)" because "this._writeCapabilities" is null
    at tools.jackson.databind.SerializationContext.isEnabled(SerializationContext.java:495) ~[jackson-databind-3.0.0-rc9.jar:3.0.0-rc9]
    at tools.jackson.databind.ser.jdk.UUIDSerializer._writeAsBinary(UUIDSerializer.java:116) ~[jackson-databind-3.0.0-rc9.jar:3.0.0-rc9]
    at tools.jackson.databind.ser.jdk.UUIDSerializer.serialize(UUIDSerializer.java:78) ~[jackson-databind-3.0.0-rc9.jar:3.0.0-rc9]
    at tools.jackson.databind.ser.jdk.UUIDSerializer.serialize(UUIDSerializer.java:23) ~[jackson-databind-3.0.0-rc9.jar:3.0.0-rc9]
    at tools.jackson.databind.SerializationContext.writeValue(SerializationContext.java:308) ~[jackson-databind-3.0.0-rc9.jar:3.0.0-rc9]
    at tools.jackson.core.base.GeneratorBase.writePOJO(GeneratorBase.java:298) ~[jackson-core-3.0.0-rc9.jar:3.0.0-rc9]
    at tools.jackson.core.JsonGenerator.writePOJOProperty(JsonGenerator.java:1850) ~[jackson-core-3.0.0-rc9.jar:3.0.0-rc9]
    at com.example.demo.ItemSerializer.serializeObject(ItemSerializer.java:13) ~[main/:na]
  • If ItemSerializer is removed (or disabled by removing @JsonComponent), the failure does not occur.
  • The reproducer app has another branch that proves the issue does not occur in Spring v3.5.6

I asked AI to explain this issue and it said the cause is a mixture of Jackson v2 and v3 libraries on the classpath. I don't know how much to trust this explanation, but I noticed that there are classes in spring-web (e.g. MappingJackson2HttpMessageConverter) that are importing Jackson v2 types such as com.fasterxml.jackson.databind.ObjectMapper.

Comment From: philwebb

This looks like a Jackson bug to me, I'll try to recreated it without Spring Boot

Comment From: wilkinsona

I agree, and have just done so:

JsonMapper mapper = new JsonMapper();
JsonGenerator generator = mapper.createGenerator(new StringWriter());
generator.writeStartObject();
generator.writePOJOProperty("id", UUID.randomUUID());
generator.writeEndObject();

@donalmurtagh please report this to the Jackson maintainers.

/cc @cowtowncoder

Comment From: cowtowncoder

Probably different issue, but there was an earlier UUID serialization with Jackson 3.0 issue:

https://github.com/FasterXML/jackson-databind/issues/5225

but that was fixed for 3.0.0-rc6

Comment From: donalmurtagh

I've reported the bug to Jackson

Comment From: cowtowncoder

Quick note: Jackson issue transferred to: https://github.com/FasterXML/jackson-databind/issues/5323