[ 
http://jira.codehaus.org/browse/JIBX-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=137860#action_137860
 ] 

Michael Bannij commented on JIBX-219:
-------------------------------------

Here is my replacement for 1.1.5's serializeDate:

    public static String serializeDate(Date date) {
        StringBuffer sb = new StringBuffer();

        Calendar c = new GregorianCalendar();
        c.setTime(date);

        String s;
        
        int year = c.get(Calendar.YEAR);
        if (year < 0) {
                year = -year;
                sb.append('-');
        }
        s = "" + year;
        addPrefix(sb, s, 4, '0');
        sb.append(s);

        sb.append('-');
        
        s = "" + (1 + c.get(Calendar.MONTH));
        addPrefix(sb, s, 2, '0');
        sb.append(s);
        
        sb.append('-');
        
        s = "" + c.get(Calendar.DAY_OF_MONTH);
        addPrefix(sb, s, 2, '0');
        sb.append(s);
        
        int offset = c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET);
        if (offset >= 0) {
                sb.append("+");
        } else {
                sb.append("-");
                offset = -offset;
        }
        
        s = "" + (int) (offset/3600000);
        addPrefix(sb, s, 2, '0');
        sb.append(s);
        
        sb.append(':');
        
        s = "" + (int) ((offset%3600000)/60000);
        addPrefix(sb, s, 2, '0');
        sb.append(s);
        
        return sb.toString();
    }

    private static void addPrefix(StringBuffer sb, String mainStr, int size, 
char fillement)
    {
        for (int l=mainStr.length(); l<size; ++l) {
                sb.append(fillement);
        }
    }


> JiBX is not ready to work with xsd:date XML type
> ------------------------------------------------
>
>                 Key: JIBX-219
>                 URL: http://jira.codehaus.org/browse/JIBX-219
>             Project: JiBX
>          Issue Type: Bug
>          Components: core
>    Affects Versions: JiBX 1.1.5
>            Reporter: Michael Bannij
>             Fix For: JiBX 1.1.6
>
>
> This is my third bugreport on JiBX (two are here and one is in Axis2 
> bugtracking system). I think it is because we are using JiBX for datmopping 
> only on one side of webservices communication.
> This time i have found two problems that appear to have the same root. First 
> problem deals with datamapping when JiBX marshals value for xsd:date element. 
> So JiBX is marshaling Date to the XML where xsd:date is expected by using 
> it's default mapping for Date. As i have found after discovering the problem, 
> in such case JiBX 1) uses standard transformation as for xsd:dateTime type, 
> and 2) when writing to XML, JiBX converts date to UTC timezone. Combination 
> of these two features makes other side to receive a date value that is 
> different from the sent value (the received date is one day before the date 
> which was sent) when the timezone on a host making request is set ahead UTC 
> (e.g., UTC+1 in my case). This is because, e.g. to sent the date "1st of 
> January, 2008" on the host having UTC+1 timezone, the jibix marshals the date 
> as datewithtime and then converts to UTC, as a result one will have somewhat 
> like "2007-12-31T23:00:00Z" in the XML. Then the receiving side, that expects 
 xsd:date here, reads just date "2007-12-31" from that XML and usially ignores 
the timezone specified. So the result in this example usially will be "31st of 
December, 2007".
> The second problem arises when JiBX is on the receiving side and is 
> unmarshaling the value that was sent as a value of xsd:date. The sender sends 
> an XML value like "2005-12-21+02:00". Then the JiBX, looking at the type in 
> valueobject (the type is usially java.util.Date) by default unmarshals the 
> xml value as a value for xsd:dateTime... and raises exception 
> JiBXException("Missing 'T' separator in dateTime"). This is done inside 
> org.jibx.runtime.Utility.parseDateTime(String).
> After i've got both the issues i've googled such conversation: 
> http://www.mail-archive.com/[EMAIL PROTECTED]/msg00110.html
> So i went to org.jibx.runtime.Utility, found the appropriate methods 
> (de)serializeDate(*) and have added such formatter to my binding.xml:
> ----------------
>   ...
>   <format type="java.util.Date"
>               label="date-without-time"
>               serializer="org.jibx.runtime.Utility.serializeDate"
>               deserializer="org.jibx.runtime.Utility.deserializeDate"/>
>   ...
>   <mapping name="MyInfoList" class="com.my.MyInfo">
>     <namespace uri="http://www.my.com/myinfo"; default="elements"/>
>     ....
>     <value name="SettlementDate" format="date-without-time" 
> field="settlementDate" usage="required"/>
>     ....
>   </mapping>
>   ...
> ----------------
> Finally, i've tried the changes in runtime... and got JiBXException("Invalid 
> date format") on the Utility:711. The text in my case was "2005-12-21+02:00", 
> the validity flag was set to false on the line Utility:707,  and when 
> executing the line 706 the value of split was 10. So the text.charAt(Split) 
> in my case was '+' and i wonder what for is the comparation 
> text.charAt(split+3) != '-' at the line 706...
> 703:        if (text.length() < minc) {
> 704:            valid = false;
> 705:        } else {
> 706:            if (text.charAt(split) != '-' || text.charAt(split+3) != '-') 
> {
> 707:                valid = false;
> 708:            }
> 709:        }
> In summary, there is no method in org.jibx.runtime.Utility that is ready to 
> deserialize xsd:date value. And to have such method is a must since xsd:date 
> is quite common type in webservices definitions. Please add such method. And 
> i think that the way one should write XSD to work with xsd:date is worth 
> going to JiBX FAQ.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jibx-devs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-devs

Reply via email to