tags:

views:

356

answers:

1

Is there a way to configure dozer via its xml mapping file to convert a primitive int field value of -1 to a null object reference?

The legacy object model defaults the value to -1, so that zero can be a valid selection.

The newer object model we are mapping to, assumes that non-selected values will be null, and that any initialized object value is valid. I'm hoping to avoid the need to write a custom converter for this case.

+1  A: 

You probably already know it, but the only solutions I can see are, either...

  1. To write a custom converter for it.
  2. Or, to write a custom setter of the destination property (in the new object model), which would take care of the -1 -> null translation.
  3. Or, to write a custom getter of the source property (in the old object model), which would take care of the -1 -> null translation.

2 and 3 are a bit worse than 1, because they pollute the old code with new values handling or the new code with old values handling.

Grzegorz Oledzki