Created
December 20, 2016 19:05
-
-
Save filiphr/91e09c3ff668c6d0411108b6c7c40c5a to your computer and use it in GitHub Desktop.
Mapstruct #1003
This file contains 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
public class Address { | |
private String street; | |
public String getStreet() { | |
return street; | |
} | |
public void setStreet(String street) { | |
this.street = street; | |
} | |
public static class Builder { | |
private String street; | |
public String getStreet() { | |
return street; | |
} | |
public void setStreet(String street) { | |
this.street = street; | |
} | |
public Address build() { | |
Address address = new Address(); | |
address.setStreet( street ); | |
return address; | |
} | |
} | |
} |
This file contains 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
public class BillingAddress { | |
private String street; | |
public String getStreet() { | |
return street; | |
} | |
public void setStreet(String street) { | |
this.street = street; | |
} | |
} |
This file contains 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
public class Input { | |
BillingAddress billingAddress; | |
public BillingAddress getBillingAddress() { | |
return billingAddress; | |
} | |
public void setBillingAddress(BillingAddress billingAddress) { | |
this.billingAddress = billingAddress; | |
} | |
} |
This file contains 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.Mapper; | |
import org.mapstruct.Mapping; | |
import org.mapstruct.Mappings; | |
@Mapper | |
public interface MyMapping { | |
Address.Builder mapAddress(BillingAddress billingAddress); | |
@Mappings( { | |
@Mapping( source = "input.billingAddress", target = "address") | |
} ) | |
PersonalDetails mapCustomer(Input input); | |
} |
This file contains 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
public class PersonalDetails { | |
private Address address; | |
public Address getAddress() { | |
return address; | |
} | |
public void setAddress(Address address) { | |
this.address = address; | |
} | |
public void setAddress(Address.Builder builder) { | |
this.address = builder.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment