Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jackson's ObjectMapper writes empty JSON strings for Spring Boot 3.1.0 if the entity is a record #35891

Closed
DManstrator opened this issue Jun 14, 2023 · 7 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@DManstrator
Copy link

DManstrator commented Jun 14, 2023

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 DManstrator/sb3-serialization-test#1 and the Checks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2023
@wilkinsona
Copy link
Member

wilkinsona commented Jun 14, 2023

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.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2023
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2023
@DManstrator
Copy link
Author

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.

@DManstrator
Copy link
Author

@wilkinsona: Small update: This is in fact a Jackson bug which was already fixed in Jackson v2.15.1, see FasterXML/jackson-databind#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?

@philwebb
Copy link
Member

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

@rdehuyss
Copy link

rdehuyss commented Jun 15, 2023

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

@scottfrederick
Copy link
Contributor

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

@rdehuyss
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

6 participants