如何排除对象 属性
How to exclude object property
我使用 Orika 映射器来映射两个 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();
}
}
我使用 Orika 映射器来映射两个 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();
}
}