#8 Blank string conversion

closed
None
5
2005-09-16
2005-09-15
No

I was using it to convert my action forms to the dto.
In this I am having a date field say registeredDate
which has to be converted into date using a given format.
Now whenever the registeredDate is blank("")... the
dozer tries to convert it and throws parseexception error.

For action forms those fields which are not fileed are
blank string by default not NULL. So how to approach this

Discussion

  • Franz Garsombke

    Franz Garsombke - 2005-09-15

    Logged In: YES
    user_id=550744

    I could not reproduce this error.

    Here is my mapping:

    <field>
    <A dateFormat="MM/dd/yyyy HH:mm:ss:SS">blankDate</A>
    <B>blankDate</B>
    </field>

    Here is the test:

    TestObject testObject = new TestObject();
    testObject.setBlankDate("");
    TestObjectPrime prime = (TestObjectPrime)
    Mapper.map(testObject, TestObjectPrime.class);

    The prime object has a blankDate which is NULL.

     
  • Franz Garsombke

    Franz Garsombke - 2005-09-15
    • status: open --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2005-09-16
    • status: pending --> open
     
  • Franz Garsombke

    Franz Garsombke - 2005-09-16

    Logged In: YES
    user_id=550744

    I fixed the bug by adding this to the DateConverter.java
    class. I added if(sourceObj.equals("") return null.

    //String to Date
    } else if (dateFormat != null &&
    String.class.isAssignableFrom(sourceObj.getClass())) {
    try {
    if(sourceObj.equals("")){
    return null;
    }
    time = dateFormat.parse( (String)
    sourceObj).getTime();
    } catch (ParseException e) {
    throw new ConversionException("Unable to parse
    source object using specified date format", e);
    }

    This will be in the 1.5.3 release...or you can patch if you
    like.

    Thanks.

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2005-09-16
    • status: open --> 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