tags:

views:

393

answers:

3

Hello,

does anybody know how to put a constant value into an attribute with dozer? I haven't seen anything about that in the dozer's documentation

+1  A: 

Not entirely sure what you mean - if you want Dozer to always populate BeanB.someField with a constant whenever you map from BeanA to BeanB?

You might want to register a custom converter for this mapping.

matt b
Yes, that is exactly what I want. I was wondering if it was possible to do it directly without a custom converter.
Pau
Thanx for the answer, by the way.
Pau
I believe your only methods are to use a custom convert or to do it by hand when you invoke Dozer. Dozer only really handles mapping from one bean to another, and doesn't give you much room to insert other logic (which makes sense, as it isn't meant to do that).
matt b
A: 

How about taking advantage of the events mechanism?

So you could register a listener which would do the setting of the value in mappingFinished() of your listener. Consult dozer doc on events for details. Of course you would have to guard the setting code with some kind of if ... instanceof condition.

Grzegorz Oledzki
A: 

Recent builds of dozer make this easier. You can specify both custom converters and you can specify parameters to that converter for a given field mapping. It should be trivial to create a single 'ConstantConverter' that will take an input parameter and put that in the output field 100% of the time.

Jherico