atos1990 / orika

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

Conversion of BigDecimal to java.lang.Double is not working #31

Closed GoogleCodeExporter closed 9 years ago

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

1. Class A containing field of type BigDecimal
2. Class B containing field of type java.lang.Double
3. Try to declare and perform conversion for such field

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

Conversion works find if class B has field of primitive unboxed type "double". 
But it fails if it does have "java.lang.Double" with exception "exception while 
creating object factory for java.lang.Double" - with message "exception while 
creating object factory for java.lang.Double".

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

1.1.5 from maven repository.

Original issue reported on code.google.com by maxim.ku...@gmail.com on 9 Jul 2012 at 12:54

GoogleCodeExporter commented 9 years ago
Did you register a converter for Double <-> BigDecimal ?

Original comment by elaat...@gmail.com on 9 Jul 2012 at 1:21

GoogleCodeExporter commented 9 years ago
Is it strictly necessary? Now see that this is required, but initially what 
confused me - that I have to register such conversion even for built-in types. 
Anyway, it would be greate to have such conversion options covered just out of 
the box. So, this is not defect, but feature request probably :)

BTW, I'm starting to think that I had another problem there with double values 
- but will take a more look and will report later.

Original comment by maxim.ku...@gmail.com on 9 Jul 2012 at 1:24

GoogleCodeExporter commented 9 years ago
There is no builtin converters (if not autoboxing) :( just to avoid unexpected 
behavior 
but we can start thinking about this feature request.

Original comment by elaat...@gmail.com on 9 Jul 2012 at 1:41

GoogleCodeExporter commented 9 years ago
In the new 1.2.0 branch, there is a (pending) capability to enable this 
behavior via a common set of default converters, like so:
   MapperFactory factory = new DefaultMapperFactory.Builder().useBuiltinConverters(true).build();
Also, the exception is improved for cases where it wasn't registered:

   ma.glasnost.orika.MappingException: While attempting the folling mapping:
   sourceType = BigDecimal
   destinationType = Double
   Error occurred: No converter registered for conversion from BigDecimal to Double, nor any ObjectFactory which can generate Double from BigDecimal

Note that this is still disabled by default, in order to avoid unexpected 
changes in behavior.

Original comment by matt.deb...@gmail.com on 9 Jul 2012 at 9:07

GoogleCodeExporter commented 9 years ago
+1 for sensible conversion of numeric types.  (Just hit the same issue).

Original comment by martyp...@mango-factory.com on 22 Aug 2012 at 10:46

GoogleCodeExporter commented 9 years ago
As mentioned in Matt comment this will be bundled in the 1.2.0,

Original comment by elaat...@gmail.com on 22 Aug 2012 at 10:51

GoogleCodeExporter commented 9 years ago
Fixed in 1.2.0 release.

Original comment by matt.deb...@gmail.com on 8 Sep 2012 at 5:05