Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12
Constructor parameter mapping
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
When mapping records into immutable classes, the DefaultRecordMapper calls a constructor. If it cannot discover the constructor's parameter names, it has to match record values to constructor parameters by position. A set of settings governs where parameter names are looked up, so that values can be matched by name instead:
-
mapConstructorParameterNamesInKotlin(defaults totrue): Whether to use the parameter names of a Kotlin class's primary constructor, which requireskotlin-reflecton the classpath. This has no effect on Java classes. -
mapConstructorParameterNames(defaults tofalse): Whether to use parameter names obtained through Java reflection, usingExecutable.getParameters(). Parameter names are only available if the class was compiled with thejavac -parametersflag.
Example configuration
Settings settings = new Settings()
.withMapConstructorParameterNames(true); // Defaults to false
Feedback
Do you have any feedback about this page? We'd love to hear it!