XStream

DateConvertor not able to handle empty/null strings from XML

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Won't Fix
  • Affects Version/s: 1.3.1
  • Fix Version/s: None
  • Component/s: Converters
  • Labels:
    None

Description

For following XML mapped to User class with fields email (string) and dob (Date)

<User><email></email><dob></dob></User>

DateConvertor throws error because, it is trying to parse empty string.

DateConvertor should be able to handle this by simply returning null (instead of throwing exception)

Activity

Hide
Joerg Schaible added a comment -

Sorry, null is not represented by an empty tag. If a field is null it is not part of the XML structure. An empty string is not a proper date format and you are feeding the converter with undefined data. You argue that you will have a null value returned instead, the next would like to have 1st January 1970 and another one prefers an exception. Therefore you have to handle this case with a customized verison of the DateConverter yourself.

Show
Joerg Schaible added a comment - Sorry, null is not represented by an empty tag. If a field is null it is not part of the XML structure. An empty string is not a proper date format and you are feeding the converter with undefined data. You argue that you will have a null value returned instead, the next would like to have 1st January 1970 and another one prefers an exception. Therefore you have to handle this case with a customized verison of the DateConverter yourself.
Hide
deepak added a comment -

Hi,

Probably I wasn't clear to explain it before. Lets take three use cases

1. For below xml it works great no issues.

<User><email>test@test.com</email><dob>2010-09-01</dob></User>

2. For below xml ALSO it works great no issues.

<User><email></email><dob>2010-09-01</dob></User>

3. But not for this - exception is thrown.

<User><email>test@test.com</email><dob></dob></User>

Why is when email field is empty its handled correctly, but not Date field

Hope this helps.

Feel free to mark it invalid/resolve if above cases look incorrect. I have found way around my problem so no more stuck because of this.

Show
deepak added a comment - Hi, Probably I wasn't clear to explain it before. Lets take three use cases 1. For below xml it works great no issues. <User><email>test@test.com</email><dob>2010-09-01</dob></User> 2. For below xml ALSO it works great no issues. <User><email></email><dob>2010-09-01</dob></User> 3. But not for this - exception is thrown. <User><email>test@test.com</email><dob></dob></User> Why is when email field is empty its handled correctly, but not Date field Hope this helps. Feel free to mark it invalid/resolve if above cases look incorrect. I have found way around my problem so no more stuck because of this.
Hide
Joerg Schaible added a comment -

If "email" is a String, an empty value is a perfect valid value from the technical side. This does not apply to a date.

Show
Joerg Schaible added a comment - If "email" is a String, an empty value is a perfect valid value from the technical side. This does not apply to a date.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: