【问题标题】:How to map Object to Object if source and destination is same如果源和目标相同,如何将对象映射到对象
【发布时间】:2021-11-26 17:55:51
【问题描述】:

我有

public class A {
    private String id;
    private Object filter;
}

我用数据构建对象 A

{
    "id":1,
    "filter" : {
      "ids":[1,2,3],
      "type": "1"
    }
}

之后

A b = mapper.map(a, A.class)

b.filter 为空。如何解决?

【问题讨论】:

    标签: java mapping orika


    【解决方案1】:
        MapperFactory build = new 
        DefaultMapperFactory.Builder().build();
        build.classMap(A.class, A.class)
                .customize(
                        new CustomMapper<>() {
                            @Override
                            public void mapAtoB(A source, A destination, MappingContext context) {
                                b.setFilter(a.getFilter());
                            }
                        }
                )
                .byDefault()
                .register();
    

    【讨论】:

      猜你喜欢
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 2018-06-18
      相关资源
      最近更新 更多