#44 custom converter(s) and primitive matching

closed
None
5
2006-04-29
2006-04-21
No

Attempting bi-directional custom conversion. toString
on TestCustomConverterObject is being employed rather
then the custom conversion. conversion from
TestCustomConverterObjectPrime to
TestCustomConverterObject works okay, but conversion
other way fails:

net.sf.dozer.util.mapping.converters.ConversionExcepti
on: org.apache.commons.beanutils.ConversionException:
For input
string: "net.sf.dozer.util.mapping.vo.CustomDoubleObje
ct@1a1c887[
theDouble=25.0
name=<null>
]"
at
net.sf.dozer.util.mapping.util.MappingUtils.convertPri
mitiveOrWrapper(MappingUtils.java:486)
at
net.sf.dozer.util.mapping.MappingProcessor.mapOrRecurs
eObject(MappingProcessor.java:523)
at
net.sf.dozer.util.mapping.MappingProcessor.mapFromFiel
dMap(MappingProcessor.java:359)
at
net.sf.dozer.util.mapping.MappingProcessor.map
(MappingProcessor.java:334)
at
net.sf.dozer.util.mapping.MappingProcessor.map
(MappingProcessor.java:108)
at
net.sf.dozer.util.mapping.DozerBeanMapper.map
(DozerBeanMapper.java:75)
at DozerBeanMapperTest.testCustomConverter
(DozerBeanMapperTest.java:69)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke
(Method.java:585)
at junit.framework.TestCase.runTest
(TestCase.java:154)
at junit.framework.TestCase.runBare
(TestCase.java:127)
at junit.framework.TestResult$1.protect
(TestResult.java:106)
at junit.framework.TestResult.runProtected
(TestResult.java:124)
at junit.framework.TestResult.run
(TestResult.java:109)
at junit.framework.TestCase.run
(TestCase.java:118)
at junit.framework.TestSuite.runTest
(TestSuite.java:208)
at junit.framework.TestSuite.run
(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
.runTests(RemoteTestRunner.java:392)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
.run(RemoteTestRunner.java:276)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
.main(RemoteTestRunner.java:167)
Caused by:
org.apache.commons.beanutils.ConversionException: For
input
string: "net.sf.dozer.util.mapping.vo.CustomDoubleObje
ct@1a1c887[
theDouble=25.0
name=<null>
]"
at
org.apache.commons.beanutils.converters.DoubleConverte
r.convert(DoubleConverter.java:164)
at
net.sf.dozer.util.mapping.util.MappingUtils.convertPri
mitiveOrWrapper(MappingUtils.java:484)
... 21 more
Caused by: java.lang.NumberFormatException: For input
string: "net.sf.dozer.util.mapping.vo.CustomDoubleObje
ct@1a1c887[
theDouble=25.0
name=<null>
]"
at
sun.misc.FloatingDecimal.readJavaFormatString
(FloatingDecimal.java:1224)
at java.lang.Double.valueOf(Double.java:447)
at java.lang.Double.<init>(Double.java:539)
at
org.apache.commons.beanutils.converters.DoubleConverte
r.convert(DoubleConverter.java:159)
... 22 more

Here is the source code for junit test case:

TestCustomConverterObjectPrime prime = new
TestCustomConverterObjectPrime();
prime.setDoubleAttribute(25.00);
TestCustomConverterObject obj =
(TestCustomConverterObject)mapper.map(prime,
TestCustomConverterObject.class);
CustomDoubleObject customDouble =
obj.getAttribute();
assertNotNull(customDouble);
assertTrue(prime.getDoubleAttribute()
==obj.getAttribute().getTheDouble());

// test conversion in the other
direction
try {
prime =
(TestCustomConverterObjectPrime)mapper.map(obj,
TestCustomConverterObjectPrime.class);
} catch (Exception e) {
// TODO Auto-generated catch
block
e.printStackTrace();
throw e;
}
assertTrue(prime.getDoubleAttribute()
==obj.getAttribute().getTheDouble());

Discussion

  • Franz Garsombke

    Franz Garsombke - 2006-04-21

    Logged In: YES
    user_id=550744

    Using the v21Branch I ran this test successfully:

    public void testCustomConverterBiDirectional() throws
    Exception {
    TestCustomConverterObjectPrime prime = new
    TestCustomConverterObjectPrime();
    prime.setDoubleAttribute(new Double(25.00));
    TestCustomConverterObject obj =
    (TestCustomConverterObject) mapper.map(prime,
    TestCustomConverterObject.class);
    CustomDoubleObjectIF customDouble = obj.getAttribute();
    assertNotNull(customDouble);
    assertTrue(prime.getDoubleAttribute().doubleValue() ==
    obj.getAttribute().getTheDouble());

    // test conversion in the other direction
    try {
    prime = (TestCustomConverterObjectPrime)
    mapper.map(obj, TestCustomConverterObjectPrime.class);
    } catch (Exception e) {
    e.printStackTrace();
    throw e;
    }
    assertTrue(prime.getDoubleAttribute().doubleValue() ==
    obj.getAttribute().getTheDouble());
    }

    Notice I had to change a couple lines to align it with our
    current test objects. Can you attach the test objects you
    were using?

    Thanks,

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2006-04-21
    • assigned_to: nobody --> fgarsombke
     
  • Brian Hickey

    Brian Hickey - 2006-04-21

    base test object

     
  • Brian Hickey

    Brian Hickey - 2006-04-21

    Logged In: YES
    user_id=1098203

    chief difference I see is the usage of the double
    primitive vs. the java.lang.Double. Should this make
    a difference?

     
  • Brian Hickey

    Brian Hickey - 2006-04-21

    Logged In: YES
    user_id=1098203

    have added the requested files and my associated
    dozerMapper.xml

     
  • Franz Garsombke

    Franz Garsombke - 2006-04-21

    Logged In: YES
    user_id=550744

    I fixed this and it is in v21Branch. Wasn't really a
    bug...we did not look at primitives in the custom converter
    code when trying to find a destination custom converter. I
    have attached the fix. Please let me know if this fixes the
    problem. This will be in the next release scheduled for next
    week.

    thanks

    franz

     
  • Franz Garsombke

    Franz Garsombke - 2006-04-21
    • summary: custom converter(s) --> custom converter(s) and primitive matching
    • status: open --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2006-04-29
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks