Sam
Sam

Reputation: 51

Orika Nested Mappers

I need to implement nested mappers using Orika. How should I need to do it? Let's discuss simple objects which are nested

Class Person(){
Address address;
String firstName;
String lastname;
}

Class Address(){
String street;
String city;
String zipcode;
}    

Lets assume that I have separate java mapper for address object. How shall I use the external Java mapper in the below field mapping in orika?

customize() option in the field mapping is to map the complex fields explicitly in the .classMap mapping, which will make the current map complex to read when the objects are pretty big.

public class Mapper extends ConfigurableMapper {
  protected void configure(MapperFactory factory) {
    factory.classMap(Person.class, PersonDto.class)
      .byDefault()
      .register();      
  }
}

Upvotes: 0

Views: 1655

Answers (1)

Sidi
Sidi

Reputation: 1739

Just register a another class map for Address and it will be used automatically by Orika when mapping a graph of objects

Upvotes: 1

Related Questions