AArhin / orika

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

Orika fails to map converter result to string (double cast) #148

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I am trying to map an object to a string via a custom converter, with the 
converter returning null (e.g. because the source object is null)

What is the expected output? What do you see instead?

Expected result: target property should be set to null
Actual result: target property is set to the string "null"

What version of the product are you using? On what operating system?
Orika 1.4.4

Please provide any additional information below.

I have attached a full test case to this issue that displays the problem. The 
source of the problem is in method 
ma.glasnost.orika.impl.generator.VariableRef.cast() in lines 354 and 386 - 
there is a comment on this already. The result of the converter is "cast" to a 
string with the expression
  "" + castValue.
Now if castValue is null, this will produce the string "null" instead of the 
value null.
A better solution would be the expression
  castValue == null ? null : castValue.toString();

because it preserves the value null and produces the same result as 
""+castValue when castValue is not null.

Original issue reported on code.google.com by daniel.b...@googlemail.com on 7 Mar 2014 at 5:48

Attachments:

GoogleCodeExporter commented 8 years ago
A fix has been pushed to the latest master; please check it out and let us know.

Original comment by matt.deb...@gmail.com on 9 Mar 2014 at 2:33

GoogleCodeExporter commented 8 years ago
Seems to be resolved in 1.4.5. Our tests now complete successfully.

Original comment by daniel.b...@googlemail.com on 25 Mar 2014 at 8:34