hi!
we are using lombok for everything and i discovered a problem when mapping back and forth between two types that use fluent and chained accessors.
the code example below adds 2 PropertyMaps, one for Dto -> Entity and one for the other way. there is just 1 mapped property which is mapped explicitly. adding either one of the PropertyMaps works while adding both results in the exception below.
is there any nice way to solve this?
Exception in thread "main" org.modelmapper.ConfigurationException: ModelMapper configuration errors:
1) Failed to configure mappings
1 error
at org.modelmapper.internal.Errors.throwConfigurationExceptionIfErrorsExist(Errors.java:241)
at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:207)
at org.modelmapper.internal.TypeMapImpl.addMappings(TypeMapImpl.java:73)
at org.modelmapper.internal.TypeMapStore.getOrCreate(TypeMapStore.java:101)
at org.modelmapper.ModelMapper.addMappings(ModelMapper.java:93)
at io.sourcy.playground.Main.main(Main.java:21)
Caused by: java.lang.ClassCastException: org.modelmapper.internal.PropertyInfoImpl$MethodMutator cannot be cast to org.modelmapper.internal.Accessor
at org.modelmapper.internal.PropertyInfoRegistry.accessorFor(PropertyInfoRegistry.java:61)
at org.modelmapper.internal.ExplicitMappingVisitor$MappingCapturingVisitor.recordSourceMethod(ExplicitMappingVisitor.java:256)
at org.modelmapper.internal.ExplicitMappingVisitor$MappingCapturingVisitor.visitEnd(ExplicitMappingVisitor.java:204)
at org.modelmapper.internal.asm.ClassReader.b(Unknown Source)
at org.modelmapper.internal.asm.ClassReader.accept(Unknown Source)
at org.modelmapper.internal.asm.ClassReader.accept(Unknown Source)
at org.modelmapper.internal.ExplicitMappingBuilder.visitPropertyMap(ExplicitMappingBuilder.java:222)
at org.modelmapper.PropertyMap.configure(PropertyMap.java:380)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:195)
... 4 more
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
public final class Main {
public static void main(String[] args) {
final ModelMapper mm = new ModelMapper();
mm.addMappings(new PropertyMap<SomeDto, SomeEntity>() {
@Override
protected void configure() {
map(source.someValue(), destination.someValueWithDifferentName(null));
}
});
mm.addMappings(new PropertyMap<SomeEntity, SomeDto>() {
@Override
protected void configure() {
map(source.someValueWithDifferentName(), destination.someValue(null));
}
});
//
//
// final SomeDto dto = new SomeDto("hello");
// final SomeEntity entity = mm.map(dto, SomeEntity.class);
// System.err.println(entity);
// final SomeDto newDto = mm.map(entity, SomeDto.class);
// System.err.println(newDto);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(fluent = true, chain = true)
public static class SomeDto {
private String someValue;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(fluent = true, chain = true)
public static class SomeEntity {
private String someValueWithDifferentName;
}
}
hi!
we are using lombok for everything and i discovered a problem when mapping back and forth between two types that use fluent and chained accessors.
the code example below adds 2
PropertyMaps, one for Dto -> Entity and one for the other way. there is just 1 mapped property which is mapped explicitly. adding either one of thePropertyMaps works while adding both results in the exception below.is there any nice way to solve this?