@Mapper
public interface SomeMapper {
class SomeDto {
public String foo; public String bar; }
class SomeEntity {
public String foo; public String bar; }
@Mapping(target = "bar", expression = "java(magic(entity.bar))") SomeDto toDto(SomeEntity entity);
default String magic(String input) { return input.toUpperCase(); }}
import javax.annotation.Generated;
@Generated( value = "org.mapstruct.ap.MappingProcessor", date = "2019-10-25T12:38:35+0200", comments = "version: 1.3.0.Final, compiler: Eclipse JDT (IDE) 3.16.0.xx-201812291959-e2018-12-RELEASE, environment: Java 11.0.1 (Oracle Corporation)")public class SomeMapperImpl implements SomeMapper {
@Override public SomeDto toDto(SomeEntity entity) { if ( entity == null ) { return null; }
SomeDto someDto = new SomeDto();
someDto.foo = magic( entity.foo );
someDto.bar = magic(entity.bar);
return someDto; }}
@Mapperpublic interface SomeMapper {
class SomeDto {
public String foo; public String bar; }
class SomeEntity {
public String foo; public String bar; }
@Mapping(target = "bar", expression = "java(Helpers.magic(entity.bar))") SomeDto toDto(SomeEntity entity);
interface Helpers {
static String magic(String input) { return input.toUpperCase(); } }}
@Mapperpublic interface SomeMapper {
class SomeDto {
public String foo; public String bar; }
class SomeEntity {
public String foo; public String bar; }
@Mapping(target = "bar", expression = "java(magic(entity.bar))") SomeDto toDto(SomeEntity entity);
@Named("workaround") default String magic(String input) { return input.toUpperCase(); }}
Hi István,
this sounds more like a feature request than an issue. I think both of your solutions are okay, as you said not that elegant.. but ok.
And I totally understand your point that the "magic" could lead
to unforeseen issues, but it also makes things less complicated.
Maybe we could introduce something like a setting that disables
this kind of implicit method resolution and requires some (new)
explicit configuration. That's just one idea...
But feel free to raise a feature request on our GitHub (https://github.com/mapstruct/mapstruct/issues) so that our team can have a look and discuss.
Thanks a lot and best regards,
Christian
--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapstruct-users/84b82221-8f84-4548-8c9f-d01669627be3%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstru...@googlegroups.com.