Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26132

Re: XStream vs XMLGregorianCalendar

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: XStream vs XMLGregorianCalendar
Date 2011-01-30 13:19 -0500
Organization albasani.net
Message-ID <ii4a25$p9f$1@news.albasani.net> (permalink)
References <d4af9ddb-16e4-4e36-b22d-fb2a1ea125e3@f2g2000yqf.googlegroups.com>

Show all headers | View raw


On 01/30/2011 04:18 AM, bw wrote:
> Friends tell me the way out!
>
> There xsd-diagram, with the help of her made JAXB java-class.
> The class is filled with data, among other things, there are element
> dateTo of the type javax.xml.datatype.XMLGregorianCalendar.
> After this class does XStream XML, I get description of this item:
> <dateTo
> class="com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl">
>       <year>2011</year>
>       <month>1</month>
>       <day>30</day>
>       <timezone>180</timezone>
>       <hour>12</hour>
>       <minute>13</minute>
>       <second>34</second>
>       <fractionalSecond>0.315</fractionalSecond>
>     </ dateTo>
>
> I do not like such a description, tell me, you can use XStream to get
> out of the XML this form:
> <dateTo>2011-01-30T09:13:34.356 Z</dateTo>?

I am certain one can, but why would you want to?

What is it that you do not like about the standard JAXB output, exactly?

I assume the "XStream" to which you refer is http://xstream.codehaus.org/, yes?

Some folks might prefer a solution without a third-party library dependency.

The main advantage of JAXB is that it handles the boilerplate mechanics of XML 
translation for you.  It also has the advantage of coming standard with the JDK.

It isn't perfect, but it's awfully good.

There are a couple of strategies to integrate JAXB-generated classes with your 
code.  Broadly, it's adapt or modify, that is, write cover classes to use the 
schema classes, or directly modify the generated code.  The work for schema 
changes is roughly the same either way, but the adapter strategy is somewhat 
more potent for deployment and enhancement.

(Another question is whether to version-control the generated .java files or 
depend on the build to create them each time.  A schema and its associated 
JAXB classes make a nice JAR.) [1]

Either way, you have to integrate the schema classes with your domain model. 
Domain objects can have muncher methods for schema graphs, or you can have 
translation layer - perhaps that very adapter layer aforementioned - that 
understands the schemas on one side and the domain on the other.

In the case of 'XMLGregorianCalendar', the Java language's official API 
thoughtfully defines the 'toGregorianCalendar()' and various 'setX()' methods 
that will help that effort.  Overall that effort should not exceed that of 
coding it using XStream's API, not accounting for JAXB's labor savings from 
the translation to 'XMLGregorianCalendar' in the first place.  Factor in the 
schema-aware methods like 'XMLGregorianCalendar#toXMLFormat()', 'compare()', 
and 'getXMLSchemaType()', and the JAXB type is a winner hands-down.

http://download.oracle.com/javase/6/docs/api/javax/xml/datatype/XMLGregorianCalendar.html

-- 
Lew
Ceci n'est pas une fenĂȘtre.
.___________.
|###] | [###|
|##/  | *\##|
|#/ * |   \#|
|#----|----#|
||    | *  ||
|o    |    o|
|_____|_____|
|===========|

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

XStream vs XMLGregorianCalendar bw <derbosebar@gmail.com> - 2011-01-30 01:18 -0800
  Re: XStream vs XMLGregorianCalendar Lew <noone@lewscanon.com> - 2011-01-30 13:19 -0500
    Re: XStream vs XMLGregorianCalendar Lew <noone@lewscanon.com> - 2011-01-30 21:51 -0500

csiph-web