-
Notifications
You must be signed in to change notification settings - Fork 682
Add support for interface projection using Kotlin "is"-properties #3127
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
Looks like a workaround is using SPEL on the projection. With changing the projection as follows, it works:
|
Just noticed now, that I created it in the wrong spring-data repository, sorry! I think it probably fits best to spring-data-commons? Can someone move it over? |
Thanks for letting us know. I moved the ticket into Spring Data Commons. |
The underlying issue is that Kotlin rewrites getters to With Spring Data 3.2 we added |
When I upgraded our existing application from Spring Boot 3.1.12 to 3.2.8 I ran into the following error, which was not present before the upgrade:
.w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Invalid property 'valid' of bean class [io.meshcloud.entitymodel_projection_issue.model.TestEntity]: Could not find field for property during fallback access]
I reproduced the issue with a minimal Spring Boot Application using Spring Data and Spring HATEOAS. The Controller is using a ProjectionFactory directly.
The entity looks like this (it has some "is"-properties):
And the projection like this (also with the "is"-properties):
When I call the controller endpoint, I get the error mentioned above. Sadly I could not get the Stacktrace for it, as the DefaultExceptionResolver just logged it as a warning.
Here is the small sample project I wrote to reproduce the issue:
failing-projection-json-mapping.zip
You can simply switch the spring boot version to 3.1.12 in there to see, that all tests in EntityModelTests succeed. But with 3.2.8 two of them fail.
I added some counter tests to see what happens if I don't use a projection or if I have a project that does not have a field starting with
is
and as expected, those cases work fine. So it seems to be something deep down in Spring Data Projections that leads to this issue.I hope I provided sufficient details for you to reproduce the issue and provide a fix for it. I would be happy for a quick workaround if you could imagine any. I will also continue finding a workaround, as I don't want to rename all affected entities in our real application to not use "is"-properties.
The text was updated successfully, but these errors were encountered: