Guerric P
Guerric P

Reputation: 31815

How to tell Orika to use ObjectFactory for nested objects when a mapper is used on the parent?

What I'm trying to achieve is to instantiate children (new references) when i use a mapper on their parent (the children exist on destination object but i want to replace them with new references). I've read in the documentation that a mapper assumes that the destination object always exists. Indeed, the code below is not working :

@Override
public void mapBtoA(FooDto b, Foo a, 
MappingContext context) {
  a = new Foo();
  a.setId(b.getId());
}

I think I should use a, ObjectFactory or a Converter but I have no idea how to call them implicitly when using a mapper on the parent.

Is that even possible ?

Upvotes: 0

Views: 474

Answers (1)

Guerric P
Guerric P

Reputation: 31815

Without conviction I tried to define a BidirectionalConverter, and when I ran my code it worked without doing anything more.

I thought Mappers and Converters were separate things but they actually work together.

Upvotes: 0

Related Questions