Bug Report

I noticed after upgrading from Spring Boot 2.7.12 to Spring Boot 3.1.0, that records cannot be serialized anymore. ObjectMapper#writeObjectAsString now returns { }. With Spring Boot 2.7.12, the serilization of records was possible. Since I found nothing in the migration guideline, I expect this to be a bug.

I created a minimal, reproducable example to show this, see https://github.com/DManstrator/sb3-serialization-test/pull/1 and the Checks.

Comment From: wilkinsona

I don't think this has anything to do with Spring Boot. Other than the Application class which the test does not use, the example does not use any Spring Boot code. The problem can be reproduced with the following:

public class Gh35891Application {

    public static void main(String[] args) throws JsonProcessingException {
        JsonMapper mapper = JsonMapper.builder()
                .enable(MapperFeature.BLOCK_UNSAFE_POLYMORPHIC_BASE_TYPES)
                .addModule(new JavaTimeModule())
                .addModule(new Jdk8Module())
                .visibility(PropertyAccessor.ALL, Visibility.NONE)
                .visibility(PropertyAccessor.FIELD, Visibility.ANY)
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                .serializationInclusion(Include.NON_NULL)
                .build();
        System.out.println(mapper.writeValueAsString(new Example(1, 2.0f, '3')));
    }

    public record Example(int a, float b, char c) {}

}

When run, it outputs {}. It appears to be related to the visibility configuration. Removing .visibility(PropertyAccessor.ALL, Visibility.NONE) results in {"a":1,"b":2.0,"c":"3"} being output. If you believe that this is a bug, it should be reported to Jackson. Before doing so, I would recommend reducing your example to something similar to the above as what you have currently shared is not minimal.

Comment From: DManstrator

Thanks for the quick feedback. I guess the problem is that the Spring Boot upgrade also updated Jackson since I make use of the spring-boot-dependencies bom. Perhaps they have changed something which causes this issue. I also thought it seems unrelated to Spring Boot but I didn't have a better idea. Due to that I didn't want to make the project as minimal as possible to not waste too much time. So sorry for the wrong issue and thanks again.

Comment From: DManstrator

@wilkinsona: Small update: This is in fact a Jackson bug which was already fixed in Jackson v2.15.1, see https://github.com/FasterXML/jackson-databind/issues/3895. However Spring Boot 3.1.0 still uses Jackson 2.15.0.

I guess in the next patch / minor update, you will also increase the Jackson version?

Comment From: philwebb

@DManstrator Correct. We have an automated process which will pick up the next Jackson release.

Comment From: rdehuyss

When will Spring Boot 3.1.1 be released? Users are also reporting errors for JobRunr related to this.

Comment From: scottfrederick

@rdehuyss Scheduled release dates are shown here: https://github.com/spring-projects/spring-boot/milestones

Comment From: rdehuyss

Thanks - makes sense 🙂. I feel like a 🤡 for not checking it...