Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java ModelMapper class

<dependency>
  <groupId>org.modelmapper</groupId>
  <artifactId>modelmapper</artifactId>
  <version>2.4.2</version>
</dependency>
Comment

java ModelMapper class

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

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);
});
Comment

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;
}
Comment

java ModelMapper class

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

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());
Comment

PREVIOUS NEXT
Code Example
Java :: java get unique elements from array 
Java :: into to string in java 
Java :: loop through array java 
Java :: why to use serializable with java bean 
Java :: how to reset jframe java swing 
Java :: Private properties in JavaScript ES6 classes 
Java :: how to count lines from txt java 
Java :: install java 8 arch 
Java :: spring boot logged in user 
Java :: border in android 
Java :: how to make hello world in java 
Java :: android.permission.INTERNET 
Java :: test if string is float java 
Java :: how to set title in center in toolbar in android 
Java :: how to change background tint color programmatically android 
Java :: java get input 
Java :: shell sort java 
Java :: java create file and parent directories 
Java :: java rps 
Java :: solid principles in programming 
Java :: i have AdoptOpenJDK 8 but java --version gettinbg Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: declare array with values java 
Java :: how to add elements in array in java using for loop 
Java :: sorting the characters of a string in java 
Java :: java random word from list 
Java :: java argument main 
Java :: java split string 
Java :: how to convert int into int array of digits in java 
Java :: how to write deserlizer java 
Java :: how to get int from string java 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =