You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by du...@apache.org on 2001/05/25 21:15:53 UTC

cvs commit: xml-soap/java/src/org/apache/soap/encoding/soapenc DateSerializer.java

duftler     01/05/25 12:15:53

  Modified:    java/src/org/apache/soap/encoding/soapenc
                        DateSerializer.java
  Log:
  Changed DateSerializer to handle unmarshalling dates with and without
    milliseconds. At some point, the acceptable date representations need to
    be more fully addressed.
  
  Revision  Changes    Path
  1.2       +19 -3     xml-soap/java/src/org/apache/soap/encoding/soapenc/DateSerializer.java
  
  Index: DateSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/encoding/soapenc/DateSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DateSerializer.java	2001/02/02 14:01:39	1.1
  +++ DateSerializer.java	2001/05/25 19:15:49	1.2
  @@ -74,16 +74,23 @@
   *
   * @author Phil Mork
   * @author Glen Daniels (gdaniels@allaire.com)
  +* @author Matthew J. Duftler (duftler@us.ibm.com)
   * @see Serializer
   * @see Deserializer
   */
   public class DateSerializer implements Serializer, Deserializer
   {
     SimpleDateFormat sdf;
  -  
  +  SimpleDateFormat sdf_ms;
  +
     public DateSerializer()
     {
  -    sdf=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  +    /*
  +      Some folks seem to give with milliseconds, some without.
  +      Let's handle both until we figure out the right thing to do.
  +    */
  +    sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  +    sdf_ms = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'");
       
       //For now just use the default locale timezone
       //sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
  @@ -137,7 +144,16 @@
         }
         catch (ParseException pe)
         {
  -        throw new IllegalArgumentException("String represents no valid Date for this Deserializer");
  +        try
  +        {
  +          date=sdf_ms.parse(value);
  +        }
  +        catch (ParseException pe2)
  +        {
  +          throw new IllegalArgumentException("String represents no valid " +
  +                                             "Date for this Deserializer; " +
  +                                             "try " + sdf.toPattern() + ".");
  +        }
         }
       }
       return new Bean(java.util.Date.class,date);