/** * 排除属性 * * @param fields 要排除的属性名称 * @return this */ public OrikaCopier.Builder<F, T> skip(String... fields) { if (fields != null && fields.length != 0) { for (String field : fields) { builder.exclude(field); } // Orika 默认使用全参构造,这时 skip() 不生效,需要使用不包含 skip 属性的构造方法, // 所以 Copiers 将默认值改为了无参构造,用户也可以在调用 skip() 后使用 constructor() 方法自己指定 // https://github.com/orika-mapper/orika/issues/135 builder.constructorB(); } return this; }
@Test public void testExcludedFields() { MapperFactory factory = new DefaultMapperFactory.Builder() .compilerStrategy(new EclipseJdtCompilerStrategy()) .build(); factory.registerClassMap(factory.classMap(Source.class, Dest.class) .exclude("id") .exclude("type") .byDefault()); factory.registerClassMap(factory .classMap(SubSource.class, SubDest.class) .use(Source.class, Dest.class).byDefault()); SubSource source = new SubSource(); source.id = "1"; source.type = "A"; source.name = "Bob"; source.age = 55; SubDest destination = factory.getMapperFacade().map(source, SubDest.class); Assert.assertNull(destination.id); Assert.assertNull(destination.type); Assert.assertEquals(source.name, destination.name); Assert.assertEquals(source.age, destination.age); }
addV2DateFields(workClassMap); registerSourceConverters(mapperFactory, workClassMap); workClassMap.exclude("workType").customize(new CustomMapper<Work, WorkEntity>() { minimizedWorkClassMap.field("workTitle.subtitle.content", "subtitle"); minimizedWorkClassMap.field("shortDescription", "description"); minimizedWorkClassMap.exclude("workType").customize(new CustomMapper<Work, MinimizedWorkEntity>() {
mapCommonFields(amendNotificationClassMap.exclude("amendedSection").customize(new CustomMapper<NotificationAmended, NotificationAmendedEntity>() { @Override public void mapAtoB(NotificationAmended a, NotificationAmendedEntity b, MappingContext context) {
workClassMap.field("workCitation.workCitationType", "citationType"); workClassMap.field("workCitation.citation", "citation"); workClassMap.exclude("workType").customize(new CustomMapper<Work, WorkEntity>() { minimizedWorkClassMap.field("workTitle.subtitle.content", "subtitle"); minimizedWorkClassMap.field("shortDescription", "description"); minimizedWorkClassMap.exclude("workType").customize(new CustomMapper<Work, MinimizedWorkEntity>() {
mapperFactory.classMap(Work.class, org.orcid.jaxb.model.v3.rc2.record.Work.class).exclude("workType").customize(new CustomMapper<Work, org.orcid.jaxb.model.v3.rc2.record.Work>() { mapperFactory.classMap(WorkSummary.class, org.orcid.jaxb.model.v3.rc2.record.summary.WorkSummary.class).exclude("type").customize(new CustomMapper<WorkSummary, org.orcid.jaxb.model.v3.rc2.record.summary.WorkSummary>() { mapperFactory.classMap(PeerReview.class, org.orcid.jaxb.model.v3.rc2.record.PeerReview.class).exclude("subjectType").customize(new CustomMapper<PeerReview, org.orcid.jaxb.model.v3.rc2.record.PeerReview>() {