commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [betwixt] Strategies for roundtripping Date objects
Date Mon, 14 Apr 2003 21:37:10 GMT
thanks eric (sorry i've been a bit slow in responding)

i'll try to take a look and see if there's maybe some way that i can make 
this easier. once the beanification of beanutils is complete, then it 
might make sense to be add a ConvertUtilsBean setter.

- robert

On Friday, April 11, 2003, at 04:21 PM, EPugh@upstate.com wrote:

> I finally got it to work!
>
> Below is my testcase for validating round tripping.  To get this to work 
> you
> need CVS Head of beanutils.  The ConvertUtils, being static, can be 
> modified
> before you start using betwixt.  The KEY was to make sure the same XML
> introspector settings are used in reading and writing!
>
> Also, I had to have leniency turned on!
>
> Eric Pugh
>
>     public void testQuickLoadSaveCycle() throws Exception
>     {
>         // To convert string to date: Thu Apr 10 17:23:20 EDT 2003
>         log.warn("\n\n\nBeginning converter create\n\n\n");
>         String pattern = "EEE MMM d hh:mm:ss z yyyy";
>         ConvertUtils utils = new ConvertUtils();
>         DateLocaleConverter converter = new
> DateLocaleConverter(Locale.getDefault(),"EEE MMM d hh:mm:ss z yyyy",true)
> ;
>
>           // test with leniency
>         converter.setLenient(true);
>
>         ConvertUtils.register(converter,java.util.Date.class);
>
>         log.warn("\n\n\nDone register\n\n\n");
>         //Technician t = (Technician)
> TechnicianList.getTechnicianList().getTechnicians().get(0);
>
>         Notification notification = new Notification();
>         notification.setComments("Dude, I am testing!");
>         notification.setDate(new Date());
>         notification.setRecipientEmail("tmckinney@upstate.com");
>        // notification.setSender(t);
>
>         ByteArrayOutputStream out = new ByteArrayOutputStream();
>         BeanWriter writer = new BeanWriter(out);
>         //      force logging to go to System.err
>         //writer.setLog(new SimpleLog("test.betwixt"));
>         writer.setWriteEmptyElements(true);
>         writer.enablePrettyPrint();
>
>         XMLIntrospector introspector = new XMLIntrospector();
>         introspector.setAttributesForPrimitives(true);
>         writer.setXMLIntrospector(introspector);
>
>         writer.write(notification);
>         out.flush();
>         String result = out.toString();
>         System.out.println(result);
>
>         BeanReader reader = new BeanReader();
>         reader.setXMLIntrospector(introspector);
>         reader.registerBeanClass(Notification.class);
>
>         Notification newNotification = (Notification) reader.parse(new
> StringReader(result));
>
>         assertNotNull("Check the date!",newNotification.getDate());
>
>     }
>
> -----Original Message-----
> From: EPugh@upstate.com [mailto:EPugh@upstate.com]
> Sent: Thursday, April 10, 2003 3:43 PM
> To: commons-dev@jakarta.apache.org
> Subject: RE: [betwixt] Strategies for roundtripping Date objects
>
>
> Okay, I now understand..  The requirement is for BeanUtils's ConvertUtils 
> to
> now be able to look up a java.util.Date converter, similar to it's 
> existing
> java.sql.Timestamp converters.  There seems to be another thread about 
> this
> being added.
>
> Presumably, when it is added, Betwixt will just pick it up?
>
> Also, therotecially, it looks like I can register my own converter with
> ConvertUtils that would work?
>
> Eric
>
> -----Original Message-----
> From: Pugh, Eric
> Sent: Thursday, April 10, 2003 3:09 PM
> To: 'Jakarta Commons Developers List'
> Subject: RE: [betwixt] Strategies for roundtripping Date objects
>
>
> Robert,
>
> I went into the source to try and submit a testcase, and it seems like my
> problem has been solved..  The testcase TestBeanReader uses java.sql.date
> and java.sql.timestamp classes, and seems to read them in easily.
>
> However, I added another property:
>
>   /**
>    * Sets the java.util.Date object.
>    * @param javaUtilDate The javaUtilDate to set
>    */
>   public void setJavaUtilDate(java.util.Date javaUtilDate) {
>     this.javaUtilDate = javaUtilDate;
>   }
>
>   /**
>    * Returns the javaUtilDate.
>    * @return java.util.Date
>    */
>   public java.util.Date getJavaUtilDate() {
>     return javaUtilDate;
>   }
>
> and I get (which I expected):
>
> ------------- Standard Error -----------------
> [WARN] MethodUpdater - -Cannot evaluate method: setJavaUtilDate on bean:
> [org.apache.commons.betwixt.CustomerBean: ID=null, name=James,
> address=[org.apache.commons.betwixt.AddressBean: street=null, city=null,
> country=null]] of type: org.apache.commons.betwixt.CustomerBean with 
> value:
> Thu Apr 10 14:55:44 EDT 2003 of type: java.lang.String
> java.lang.IllegalArgumentException: argument type mismatch
> 	at java.lang.reflect.Method.invoke(Native Method)
> 	at
> org.apache.commons.betwixt.expression.MethodUpdater.update(MethodUpdater.
> jav
> a:141)
>
> Now, how do the java.sql.* types convert?  There doesn't seem to be any
> .betwixt or other funky magic!
>
> Thanks,
>
> Eric Pugh
>
> -----Original Message-----
> From: robert burrell donkin
> [mailto:robertburrelldonkin@blueyonder.co.uk]
> Sent: Wednesday, April 02, 2003 2:10 PM
> To: Jakarta Commons Developers List
> Subject: Re: [betwixt] Strategies for roundtripping Date objects
>
>
> hi eric
>
> did you miss my post?
>
> http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=104922470020557&w=2
>
> (making a .betwixt file is pretty easy but i'm not sure that it'll do any
> good.)
>
> - robert
>
> On Wednesday, April 2, 2003, at 07:50 PM, EPugh@upstate.com wrote:
>
>> I recieved any feedback on this..  I will take a looksee at tweaking how
>> betwixt works and what is involved in making a .betwixt file, however, if
>> anyone has any samples, that would be much appreciated!
>>
>> eRic
>>
>> -----Original Message-----
>> From: EPugh@upstate.com [mailto:EPugh@upstate.com]
>> Sent: Tuesday, April 01, 2003 11:05 AM
>> To: commons-dev@jakarta.apache.org
>> Subject: [betwixt] Strategies for roundtripping Date objects
>>
>>
>> Hi all,
>>
>> I am using betwixt to take a basic object with lots of string parameters
>> and
>> roundtrip them to XML and back.  However, I just added a java.util.Date
>> object, and now betwixt is erroring when it tries to pass the String
>> representation of the date object back in as a string.  I could add a
>> method
>>
>> public void setDate(String dateAsString)
>>
>> but that seems icky.  Do I have to create a .betwixt file to deal with
>> this?
>> Or, should betwixt be changed to look at my String and try and convert it
>> to
>> a date if my only matching method signature takes a date.  Alternatively
>> to
>> create a .betwixt file, can I do the same thing, but programatically.  I
>> don't really want to add yet another file for mapping.
>>
>> Loving Betwixt!
>>
>> Eric Pugh
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message