-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Jackson auto configuration error causes Spring Messaging MappingJackson2MessageConverter conversion failure #42609
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
Comments
Spring Framework set You can enable it by configuration properties: spring.jackson.mapper.default-view-inclusion: true |
I believe that unless there's a specific reason, Spring Boot should set the default value of DEFAULT_VIEW_INCLUSION to true. When it is set to false, the org.springframework.messaging.converter.MappingJackson2MessageConverter will fail. It took me two days of debugging to find this configuration, and it posed an obstacle for using Spring Messaging. |
There is a specific reason, which can be found here (in a migrated issue from 2014). |
Thanks for the report, but as explained above, Spring Boot is just picking up Spring Framework's default configuration and we don't want to override that as it is |
Oh, that sounds reasonable. We should expect Jackson-databind's readerWithView() method to work even when DEFAULT_VIEW_INCLUSION is set to false. I believe this is a bug in Jackson-databind. |
It's designed feature, why do you think it's a bug of jackson-databind? |
Class<?> view = SimpleStockFreezeStatusMessage.class;
JavaType javaType = objectMapper.constructType(new TypeReference<SimpleStockFreezeStatusMessage>() {});
//this is Spring message Usage
var value2 = (SimpleStockFreezeStatusMessage)objectMapper.readerWithView(view).forType(javaType).readValue(json);
System.out.println("message ser by readerWithView: " + value2.tenantId);
//fail tenantId is null
assertEquals(value2.tenantId, "first"); In this code, I have explicitly specified the "View", so even with DEFAULT_VIEW_INCLUSION set to false, it should successfully return the object. However, right now, the returned object has all its properties as null. Isn't this a bug? And this is exactly how |
You're right, I made a mistake; I misunderstood readerWithView(),This is indeed not a bug, but it's still quite puzzling that Spring Messaging doesn't work correctly by default. It's especially challenging when using Java instead of Kotlin, as there are no null checks, and without any exceptions being thrown, it makes troubleshooting much more difficult. |
I think you misunderstood |
Uh oh!
There was an error while loading. Please reload this page.
There are some issues with the ObjectMapper generated by the default configuration in the Spring context. When using the readerWithView() method to deserialize objects, it results in an error (all properties of the generated object are null). This directly affects Spring Messaging because MappingJackson2MessageConverter uses this method for deserialization, causing failures in Spring Messaging. However, when I use an ObjectMapper created with Jackson's default configuration, the issue does not occur. I created a Test project kotlin , java to verify this, and below is the simplified code for the test:
Different:
Spring ObjectMapper: MapperFeature.DEFAULT_VIEW_INCLUSION is false
Default ObjectMapper: MapperFeature.DEFAULT_VIEW_INCLUSION is true
I don't know this a wrong configuration or Jackson's bug!
Spring boot version is 3.3.4
The same issue also exists in version 3.2.9
The text was updated successfully, but these errors were encountered: