“Java ModelMapper Class” Respostas de código

Java ModelMapper Class

<dependency>
  <groupId>org.modelmapper</groupId>
  <artifactId>modelmapper</artifactId>
  <version>2.4.2</version>
</dependency>
Creepy Chicken

Java ModelMapper Class

ModelMapper modelMapper = new ModelMapper();
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
Creepy Chicken

Java ModelMapper Class

// Assume getters and setters
class OrderDTO {
  String customerFirstName;
  String customerLastName;
  String billingStreet;
  String billingCity;
}
Creepy Chicken

Java ModelMapper Class

assertEquals(order.getCustomer().getName().getFirstName(), orderDTO.getCustomerFirstName());
assertEquals(order.getCustomer().getName().getLastName(), orderDTO.getCustomerLastName());
assertEquals(order.getBillingAddress().getStreet(), orderDTO.getBillingStreet());
assertEquals(order.getBillingAddress().getCity(), orderDTO.getBillingCity());
Creepy Chicken

Java ModelMapper Class

// Assume getters and setters on each class
class Order {
  Customer customer;
  Address billingAddress;
}

class Customer {
  Name name;
}

class Name {
  String firstName;
  String lastName;
}

class Address {
  String street;
  String city;
}
Creepy Chicken

Java ModelMapper Class

modelMapper.typeMap(Order.class, OrderDTO.class).addMappings(mapper -> {
  mapper.map(src -> src.getBillingAddress().getStreet(),
      Destination::setBillingStreet);
  mapper.map(src -> src.getBillingAddress().getCity(),
      Destination::setBillingCity);
});
Creepy Chicken

Respostas semelhantes a “Java ModelMapper Class”

Perguntas semelhantes a “Java ModelMapper Class”

Mais respostas relacionadas para “Java ModelMapper Class” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código