UnsupportedOperationException: No accessor to set property for Kotlin data classes using parametrized types
See original GitHub issueTo reproduce:
Create an entity using a Kotlin data class:
data class User(
val id: String? = null,
val flags: Map<String, Any>,
)
Trying to save an instance with null id will crash:
No accessor to set property private final java.lang.String com.example.User.id!
java.lang.UnsupportedOperationException: No accessor to set property private final java.lang.String com.example.User.id!
at com.example.User_Accessor_a89b9l.setProperty(Unknown Source)
at org.springframework.data.mapping.model.InstantiationAwarePropertyAccessor.setProperty(InstantiationAwarePropertyAccessor.java:104)
at org.springframework.data.mapping.model.ConvertingPropertyAccessor.setProperty(ConvertingPropertyAccessor.java:63)
at org.springframework.data.mongodb.core.EntityOperations$AdaptibleMappedEntity.populateIdIfNecessary(EntityOperations.java:690)
Changing field to Map<String, String>
makes the bug disappear. Downgrading to Spring Boot 2.4.3 also removes the exception.
A minimal project reproducing the bug can be found here: https://github.com/pkubowicz/spring-data-id-accessor
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
No accessor to set property" with kotlin - Stack Overflow
to create a new instance that contains the changed property value. Alternatively: Use Kotlin's data class feature.
Read more >Kotlin: UnsupportedOperationException for reified generic ...
Kotlin : UnsupportedOperationException for reified generic with get/set operator · I have two Kotlin extension methods for the same class, but with a...
Read more >spring-projects/spring-data - Gitter
And I'm getting this exception java.lang.UnsupportedOperationException: No accessor to set property @org.springframework.data.annotation.Id()private final java.
Read more >Data classes | Kotlin
Data classes. It is not unusual to create classes whose main purpose is to hold data. In such classes, some standard functionality and...
Read more >Groovy Language Documentation
Use this data type for simple flags that track true/false conditions. ... a foo and a Foo property, since they would have the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My test case is passing when i use spring-data-commons-2.4.7-SNAPSHOT. Thanks for fixing.
Using Spring Data Commons 2.5.0-SNAPSHOT my app also works again.