Created
October 31, 2018 21:38
-
-
Save nestharus/484af2ce7563d756814dc102e2bec1df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTest { | |
public static class A_MODEL { | |
public B_MODEL b; | |
public C_MODEL c; | |
} | |
public static class A_DTO { | |
public B_DTO b; | |
} | |
public static class B_MODEL { | |
public String name; | |
} | |
public static class C_MODEL { | |
public B_MODEL b; | |
public String name; | |
} | |
public static class B_DTO { | |
public String n; | |
public C_DTO c; | |
} | |
public static class C_DTO { | |
public String n; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mapstruct.Qualifier; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
interface MapperTest { | |
@Qualifier | |
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.CLASS) | |
@interface Dto { } | |
@Qualifier | |
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.CLASS) | |
@interface Model { } | |
@Qualifier | |
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.CLASS) | |
@interface Pipe { } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mapstruct.*; | |
import org.springframework.stereotype.Service; | |
import static ClassTest.*; | |
@Service | |
@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR, uses = { | |
MapperTestB.class, | |
MapperTestC.class | |
}) | |
interface MapperTestA extends MapperTest { | |
@Mapping(target = "b", source = "source", qualifiedBy = Pipe.class) | |
A_DTO map(final A_MODEL source); | |
@Mapping(target = "b", source = "b", qualifiedBy = Model.class) | |
@Mapping(target = "c", source = "source", qualifiedBy = Pipe.class) | |
A_MODEL map(final A_DTO source); | |
@Mapping(target = "bn", source = "b") | |
@Mapping(target = "cn", source = "c") | |
MapperTestB.PipePackage pipeB(final A_MODEL source); | |
@Mapping(target = "model", source = "b", qualifiedBy = Model.class) | |
@Mapping(target = "source", source = "b.c") | |
MapperTestC.PipePackage pipeC(final A_DTO source); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mapstruct.*; | |
import org.springframework.stereotype.Service; | |
import static ClassTest.*; | |
@Service | |
@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR, uses = { | |
MapperTestC.class | |
}) | |
interface MapperTestB extends MapperTest { | |
@Dto | |
@Mapping(target = "n", source = "source.name") | |
@Mapping(target = "c", source = "cModel", qualifiedBy = MapperTestC.Dto.class) | |
B_DTO map(final B_MODEL source, final C_MODEL cModel); | |
@Model | |
@Mapping(target = "name", source = "n") | |
B_MODEL map(final B_DTO source); | |
@Pipe default B_DTO pipe(final PipePackage source) { | |
return map(source.bn, source.cn); | |
} | |
class PipePackage { | |
public B_MODEL bn; | |
public C_MODEL cn; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mapstruct.*; | |
import org.springframework.stereotype.Service; | |
import ClassTest.*; | |
@Service | |
@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) | |
interface MapperTestC extends MapperTest { | |
@Dto | |
@Mapping(target = "n", source = "name") | |
C_DTO map(final C_MODEL source); | |
@Model | |
@Mapping(target = "name", source = "source.n") | |
@Mapping(target = "b", source = "bModel") | |
C_MODEL map(final C_DTO source, final B_MODEL bModel); | |
@Pipe default C_MODEL pipe(final PipePackage source) { | |
return map(source.source, source.model); | |
} | |
class PipePackage { | |
public C_DTO source; | |
public B_MODEL model; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following works perfectly, but still have the pipes
package us.alchemy.connect.DTOs;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Qualifier;
import org.springframework.stereotype.Service;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@service
@Mapper(componentModel = "spring")
public interface MapperTest {
// mappings
@mapping(target = "b", source = "source", qualifiedBy = Pipe.class)
A_DTO map(final A_MODEL source);
}