[英]How to exclude object property
我使用Orika mapper來映射兩個bean。 我想在映射時排除billingSummary.billableItems屬性。 我正在嘗試下面的選項,但它不起作用。
有幫助嗎?
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();
}
}
您可以做的是向mapperFactory
添加另一個映射,以便定義您希望如何將BillingSummary
映射到自身。 這樣,從Cart
到FilteredCart
映射時,您可以配置為排除以映射billableItems
。
因此,您的CartMapper
將如下所示:
@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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.