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
We tried to use together Java Records (Java 21) and ModelMapper (3.1.1) and added this dependency to our project.
However the conversion still fails.
Here's source code:
public class Starter {
public static void main(String[] args) {
ModelMapper modelMapper = new ModelMapper();
modelMapper.registerModule(new RecordModule());
MyClass obj = new MyClass();
MyRecord record = modelMapper.map(obj, MyRecord.class);
}
public static record MyRecord(int i) {}
public static class MyClass {
public int i;
}
}
Here's exception:
Exception in thread "main" org.modelmapper.MappingException: ModelMapper mapping errors:
1) Failed to instantiate instance of destination com.example.demo.Starter$MyRecord. Ensure that com.example.demo.Starter$MyRecord has a non-private no-argument constructor.
1 error
at org.modelmapper.internal.Errors.throwMappingExceptionIfErrorsExist(Errors.java:386)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:80)
at org.modelmapper.ModelMapper.mapInternal(ModelMapper.java:589)
at org.modelmapper.ModelMapper.map(ModelMapper.java:422)
at com.example.demo.Starter.main(Starter.java:14)
Caused by: java.lang.NoSuchMethodException: com.example.demo.Starter$MyRecord.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3761)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2930)
at org.modelmapper.internal.MappingEngineImpl.instantiate(MappingEngineImpl.java:336)
at org.modelmapper.internal.MappingEngineImpl.createDestination(MappingEngineImpl.java:351)
at org.modelmapper.internal.MappingEngineImpl.typeMap(MappingEngineImpl.java:140)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:114)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:71)
... 3 more
The text was updated successfully, but these errors were encountered:
Hi
We tried to use together Java Records (Java 21) and ModelMapper (3.1.1) and added this dependency to our project.
However the conversion still fails.
Here's source code:
Here's exception:
The text was updated successfully, but these errors were encountered: