3

I using Orika mapper to map two beans. i would like to exclude billingSummary.billableItems property while mapping. I am trying below option but it is not working.

Any help?

public class Cart { private String id; private String name; private BillingSummary billingSummary; private String address; //with getter and setter methods } public class BillingSummary { private String billingItem; private String billingItemId; private BillableItems billableItems; ... // with getter setter methods } //FilteredCart is same as Cart. public class FilteredCart { private String id; private String name; private BillingSummary billingSummary; private String address; //with getter and setter methods } @Component public class CartMapper extends ConfigurableMapper { @Override public void configure(MapperFactory mapperFactory) { mapperFactory.classMap(Cart.class,FilteredCart.class).exclude("billingSummary.billableItems").byDefault().register(); } } 
2
  • Is it correct billableItems in the mapping exclude? From your code, I can see billingItems Commented Feb 5, 2018 at 23:00
  • I have corrected it. I forgot to keep it in the initial request. Thank you Commented Feb 5, 2018 at 23:58

1 Answer 1

3

What you can do is adding another mapping to the mapperFactory in order to define how you want to map the BillingSummary to itself. In this way, when mapping from Cart to FilteredCart, you can configure to exclude to map the billableItems.

Therefore, your CartMapper will look like this:

@Component public class CartMapper extends ConfigurableMapper { @Override public void configure(MapperFactory mapperFactory) { mapperFactory.classMap(BillingSummary.class, BillingSummary.class).exclude("billableItems").byDefault().register(); mapperFactory.classMap(Cart.class,FilteredCart.class).byDefault().register(); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.