Thanks Munjal!

I didnt think about if it was possible to just do a serializer, your
example worked perfectly, thank you very much for the help!

On 1/8/08, Munjal Kansara <[EMAIL PROTECTED]> wrote:
> Hi RJ,
>
> Wondering why you are hesitating in writing new serializer which can solve
> this issue without impacting all code that import the document (as
> serializer will not affect deserialization process -- i.e. reading)
>
> You can apply serializer globally or locally to element. Global example i
> mentioned previously for element specific it can be
>
>         <value    name="dateElementName"
>                 field="dateFieldName"
>                 serializer="com.util.JiBXSerializerUtil.dateToW3CDateString"
> />
>
> This way only writing to xml is changed conversion from XML element to Java
> Object is default (no change)...
>
> To make things easy, you can do following (applied it globally)
>     <format type="java.util.Date"
>             serializer="com.util.JiBXSerializerUtil.dateToW3CDateString" />
>
> public class JiBXSerializerUtil {
> ...
> /**
>      * Will generate this format
>      * 2000-05-01T00:00:00.000-04:00
>      *
>      * See http://www.w3.org/TR/NOTE-datetime
>      * YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
>      *
>      * @param date
>      * @return
>      */
>     public static String dateToW3CDateString(Date date){
>         //System.out.println("dateToW3CDateString invoked");
>         //Can not create static instance as this
>         //class is not thread safe -- else we may have to synchronize method
>         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:
> ss.SSSZ");
>         String sDate =sdf.format(date);
>         //as this is not in correct format of time zone for xsd:dateTime
> twake with it
>         sDate = sDate.substring(0, sDate.length() - 2) + ":"+
> sDate.substring(sDate.length() - 2);
>         return sDate;
>     }
> ...
>
> Hope this helps...
>
> Munjal
>
>
> On Jan 8, 2008 9:17 AM, Ronald Johnson <[EMAIL PROTECTED]> wrote:
>
> > Hi Munjal,
> >
> > thanks much for digging up that info.
> >
> > My problem is that i want the behaviour to be exactly as before (e.g.
> > accept the various input formats in xml etc), with the only difference
> > that when converting from
> > object to xml, there should be no conversion to GMT.
> >
> > So i wanted to avoid having to write new de/serializers that is doing
> > that is pretty much the same as the default ones, especially since I
> > do not want to jeopardize any code that is using this binding to
> > import xml documents.
> >
> > I was hoping I could find the default serializer in the source and
> > modify the actual time conversion, but could not find it.
> >
> > the real proper solution is probably to use GMT internally througout
> > our application, unfortunately we cannot make such a massive change in
> > the application at this stage.
> >
> > cheers,
> >
> > RJ
> >
> >
> > On 1/8/08, Munjal Kansara <[EMAIL PROTECTED]> wrote:
> > > Hi Ronald,
> > >
> > > This may be helpful to you
> > >
> > > http://jibx.sourceforge.net/details/conversions.html
> > >
> > > java.util.Date Date.default
> > >
> > > Converts instances of java.util.Date to and from the schema dateTime
> > > representation (a text representation like "2000-03-21T01:33:00", with
> > > optional trailing fractional seconds, and difference from UTC). Since
> > schema
> > > doesn't have any concept equivalent to Java time zones, this conversion
> > > always serializes times as UTC values (identified by a trailing "Z").
> > When
> > > deserializing times which do not include a "Z" or offset from UTC it
> > treats
> > > the values as UTC.
> > >  java.sql.Date SqlDate.default
> > >
> > > Converts instances of java.sql.Date to and from the schema date
> > > representation (a text representation like "2000-03-21").
> > >
> > > use it with format element
> > >
> > > http://jibx.sourceforge.net/details/format-element.html
> > >
> > > You can use example20 in tutorial for same....
> > >
> > > and for example it will be something like following in your binding
> > > defination
> > >
> > > <binding>
> > > ....
> > > <!-- this will applay global date formating for this binding -->
> > > <format type="java.util.Date"
> > >             serializer=" your format class "
> > >             deserializer=" your format class "/>
> > > <mapping>
> > > ...
> > > </binding>
> > >
> > > Hope this will help.
> > >
> > > Munjal
> > >
> > > On Jan 8, 2008 8:52 AM, Ronald Johnson <[EMAIL PROTECTED]> wrote:
> > >
> > > > Hi,
> > > >
> > > > i have the problem that my object that contains a java.util.Date,
> > > > which i have in CET (since i guess the jvm is having it as time
> > > > zone?),
> > > > gets convert to GMT when I use jibx to generate xml.
> > > >
> > > > I would like jibx to convert the date "as it is", and not use any time
> > > > zone conversion.
> > > >
> > > > Is there any way around that, or does anyone have code for a
> > > > serializer that will do it nicely for me?
> > > >
> > > > Since the jibx mapping is used elsewhere in the project to create java
> > > > objects from xml, i would like to keep the behaviour just as before
> > > > apart from the date conversion when creating xml from java object.
> > > >
> > > > Any tips or pointers would be much appreciated,
> > > >
> > > > cheers,
> > > >
> > > > RJ
> > > >
> > > >
> > -------------------------------------------------------------------------
> > > > Check out the new SourceForge.net Marketplace.
> > > > It's the best place to buy or sell services for
> > > > just about anything Open Source.
> > > >
> > > >
> > >
> >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > > > _______________________________________________
> > > > jibx-users mailing list
> > > > jibx-users@lists.sourceforge.net
> > > > https://lists.sourceforge.net/lists/listinfo/jibx-users
> > > >
> > >
> >
> > -------------------------------------------------------------------------
> > Check out the new SourceForge.net Marketplace.
> > It's the best place to buy or sell services for
> > just about anything Open Source.
> >
> >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> > _______________________________________________
> > jibx-users mailing list
> > jibx-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/jibx-users
> >
>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to