You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says Synthetic Constructors Should not be considered by org.springframework.data.mapping.model.PreferredConstructorDiscoverer as it is also common for them not to have correct parameter names to map to fields.
Exmaple, in Kotlin combined with Spring Data Mongo
The following class (just a dumbed down example):
@Document
data class Address @PersistenceConstructor constructor(
val postcode: String,
val state: String,
var streetAddress: StreetAddress? = null
)
Will cause Kotlin to generate 2 constructors (because of the use of "default" parameter:
@PersistenceConstructor public Address(String postcode,String state,StreetAddress streetAddress) { ... }
and
@PersistenceConstructor public /* synthetic */ Address(String arg0, String arg1, StreetAddress arg2, int arg3, DefaultConstructorMarker arg4) { ... }
PreferredConstructorDiscoverer in random order (sometimes it will, sometimes it won't, due to order of the constructors in bytecode) will pick the synthetic constructor which will cause a MappingException with message: No property null found on entity Address to bind constructor parameter to! Notice the null value. That is because the synthetic constructor does not have parameter meta data.
Roman Rodov opened DATACMNS-1082 and commented
As the title says Synthetic Constructors Should not be considered by org.springframework.data.mapping.model.PreferredConstructorDiscoverer as it is also common for them not to have correct parameter names to map to fields.
Exmaple, in Kotlin combined with Spring Data Mongo
The following class (just a dumbed down example):
Will cause Kotlin to generate 2 constructors (because of the use of "default" parameter:
and
PreferredConstructorDiscoverer in random order (sometimes it will, sometimes it won't, due to order of the constructors in bytecode) will pick the synthetic constructor which will cause a MappingException with message: No property null found on entity Address to bind constructor parameter to! Notice the null value. That is because the synthetic constructor does not have parameter meta data.
I have a PR ready, which is super simple I guess
Affects: 2.0 M3 (Kay), 1.13.3 (Ingalls SR3)
Referenced from: pull request #225
Backported to: 1.13.4 (Ingalls SR4), 1.12.11 (Hopper SR11)
The text was updated successfully, but these errors were encountered: