atos1990 / orika

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

Converter not called when value is null #79

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Register a custom converter that will return a "true" result when canConvert 
is called.
2. Pass in a null value.
3. Observe that the converter is never called.

See attached test case, testAToBNull.

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

Expecting call to converter, asking converter how to convert a null.

What version of the product are you using? On what operating system?
1.4.0/Java7/Windows

Please provide any additional information below.

Original issue reported on code.google.com by benjamin...@gmail.com on 22 Jan 2013 at 12:27

Attachments:

GoogleCodeExporter commented 9 years ago
Sorry for the late reply, I will take a look at ASAP.

Thanks for the report and test case :)

Original comment by elaat...@gmail.com on 23 Jan 2013 at 10:40

GoogleCodeExporter commented 9 years ago
This is standard behavior (at least currently)...converters don't get called 
for nulls.

We could potentially add this as enhancement, but it could be pretty 
disruptive...maybe it should be an option that can be set at 
global/classmap/fieldmap levels?

Original comment by matt.deb...@gmail.com on 30 Jan 2013 at 7:13

GoogleCodeExporter commented 9 years ago
Hello everyone,

I run into this too. I admit it's not very typical situation, but sometimes it 
would be handy.

Maybe Converters could have convertsNull() method returning boolean, which 
could signal if it is desired behaviour for given converter.

Would be definitelly nice to have.

Original comment by tomas.ho...@gmail.com on 7 Feb 2013 at 12:14

GoogleCodeExporter commented 9 years ago

Original comment by elaat...@gmail.com on 8 Feb 2013 at 12:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'd like to see this option as well.  I have several cases of needing this.

What about a new method on FieldMapBuilder I could call upon each field map to 
tell it whether or not to use the converter in the case of nulls?  Default 
would be false (it does not apply for nulls), since that's the current 
behavior.  For example:

dtoMapperFactory.getMapperFactory()
.classMap(ObjA.class, ObjB.class)
.fieldMap("state", "status")
.converter("myConverterId")
.useConverterForNulls(true)
.add()
.register();

Original comment by matthew....@gmail.com on 27 Aug 2013 at 3:53

GoogleCodeExporter commented 9 years ago
Is there already a patch to this bug? We need this very much. Thanks

Original comment by w.yu...@gmail.com on 9 Oct 2013 at 1:26

GoogleCodeExporter commented 9 years ago
We also need this, but I'm not sure what would be the best way.

A flag in the Converter that controls whether null mappings are supported makes 
sense. By default it returns false so all existing Converters will work as 
expected. If we combine that with mapNulls(InReverse) then it should cover all 
use cases I can think of.

Original comment by l.brueni...@googlemail.com on 15 Nov 2013 at 10:11

GoogleCodeExporter commented 9 years ago
Is there any update on this issue? Is somebody actively working on it? Do you 
guys need collaboration to make it happen? Just let me know, I can take a look.

Regards.

Original comment by nicolasa...@gmail.com on 4 Nov 2014 at 11:24

GoogleCodeExporter commented 9 years ago
I am hitting this issue. The current behavior of one of the field in my case is 
to do Strings.NullToEmpty(). Thus, I wrote a converter for that.

The converter is not getting called! :-(

Original comment by mpoitras...@gmail.com on 24 Dec 2014 at 6:57

GoogleCodeExporter commented 9 years ago
I also run into this issue. Want to convert a null value to a default value 
which is a pretty normal use case I think.

Original comment by c.moetz...@gmail.com on 19 Jan 2015 at 3:59