404-not-find / orika

Automatically exported from code.google.com/p/orika
2 stars 0 forks source link

BidirectionalConverter For Update Functionality #182

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

I have implemented a CustomConveter in my code and then i have registered it

public class OrderFormOrderConvertor extends BidirectionalConverter<OrderForm, 
Order> {

@Override
public Order convertTo(OrderForm orderForm, Type<Order> Order) {
   /*my code**/
}

public Order convertFrom(Order order, Type<OrderForm> orderForm) {
   /*my code**/
}

class OrderForm{
    String name;
    String code;
    String desc;

}

class Order{
    String name;
    OrderStatus status;
}

class OrderStatus{
    String code;
    String desc;
}

However, converter doesnt work totally in case of update functionality.In this 
case,it just maps the matching fields automatically.My requirement is that, it 
should map the internal object also. i.e OrderStatus object.
Below is the code for calling the map method. Please note, second parameter is 
an already instantiated object. 

ex . mapperFacade.map(orderForm,order); 

Usually for mapping, we pass first argument as the instance of source and 
second argument as .class

ex mapperFacade.map(orderForm,Order.class)

My understanding is that, it should not invoke the convertTo/From methods which 
is a correct behavour but there should be some facility where i can specify the 
mapping for the inner objects in Source and Destination.

Original issue reported on code.google.com by mandarch...@gmail.com on 18 Nov 2014 at 6:44

GoogleCodeExporter commented 8 years ago
Orika support two main mapping operations, 
map to Class : Orika will create new instance and copy data between each field
map in place : you provide two instances and Orika copy data

When you provide an instance Orika don't call the converter because it do only 
the copy 

For you use can you need to define mapping rules between this two class instead 
of a  converter.
you can also register CustomMapper and then you have mapAToB and mapBToA 
(bi-directional)

Original comment by elaat...@gmail.com on 18 Nov 2014 at 10:16