Search code examples
orika

Orika must have public setter


I'm trying Orika and I'm wondering if you have to have public setter for the mapping to work ?

I tried without setter, it's not working, neither trying to explicitly tell byDefault() :

factory.classMap(Page.class, PageResource.class).byDefault().register();

any feedback on this one ?


Solution

  • In the default Orika configuration, mapped objects have to follow the JavaBean spec with getter/setter. Another possible way is, having public fields.

    To change this behavior you can write your own PropertyResolverStrategy and configure it.

    DefaultMapperFactory build = new DefaultMapperFactory.Builder()
                .propertyResolverStrategy(new MyCustomPropertyResolvingStrategy())
                .build();
    

    see the documentation or the orika code for more information on this topic.