Search code examples
javaorika

How can I discover if a mapper has been created for two classes in Orika?


So I am writing a Telematics application and we are slowly building up mappers for DTOs. There will soon be over 100 but right now we have 3. We want to send all messages to our mapper but when we do and Orika doesn't know about it, it throws an exception.

I need a .isMapperAvailable(class, class) method but cannot find one. I did find a .existsRegisteredMapper(Type, Type) but can't figure out how it works. Any help?


Solution

  • I think you could use it like this:

    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    
    ClassMapBuilder<Foo, Bar> map = mapperFactory.classMap(Foo.class, Bar.class);
    
    Type<Foo> fooType = map.getAType();
    Type<Bar> barType = map.getBType()
    
    boolean exists = mapperFactory.existsRegisteredMapper(fooType, barType, false);