How to map Object to Object if source and destination is same

286 views Asked by At

I have

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

I build Object A with data

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

After

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

b.filter is empty. How to fix it?

1

There are 1 answers

0
AbrA On
    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();