Dozer Function Improvment Suggestion

22 views
Skip to first unread message

朱国伟

unread,
Mar 1, 2015, 4:09:13 AM3/1/15
to dozer-...@googlegroups.com
hi, 
    In recent development, I found dozer is not very convenient. My requirement described below:
query string (request.getParameterMap) --> DTO --> Domain Object.

1. Attribute names in DTO must as same as query param. For example,
query string:
?payment_code=12345678
DTO:
private String payment_code

2. if the Domain Object's attribute name is inconsistent with DTO's,eg.
Domain Object:
private String orderId;
So in this situation, you can't simply using @Mapping("orderId") in DTO for converting DTO to Domain Object successfully.Because if you do so, it will throw exception like this when you convert query params to DTO:
org.dozer.MappingException: No such field found java.util.HashMap.orderId

So after several unsuccessful attempts, finally I found a solution.
That is supply addtional getter/setter method in DTO, for example:
DTO
private String payment_code;
//getter and setter for payment_code here
//addtional getter and setter for successully converting to Domain Object
public String getOrderId(){return paymnet_code;}
public void setOrderId(){}

 Now query params --> DTO ok, and DTO-->Domain Object ok too.
But you know there are many params not only payment_code(e.g. service_id, user_id,credit_name,creadit_amount and so on),  so iot's terrible to add so many addtional getter/setter methods.
Apart from above, value of request.getParameterMap is string array, not string, so at first I have to covert this Map to common hashmap.

So can optimise dozer for this situation?

 
Reply all
Reply to author
Forward
0 new messages