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


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

Re: XStream vs XMLGregorianCalendar

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!weretis.net!feeder4.news.weretis.net!news.albasani.net!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: XStream vs XMLGregorianCalendar
Date Sun, 30 Jan 2011 13:19:06 -0500
Organization albasani.net
Lines 73
Message-ID <ii4a25$p9f$1@news.albasani.net> (permalink)
References <d4af9ddb-16e4-4e36-b22d-fb2a1ea125e3@f2g2000yqf.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.albasani.net GCnx4aCuI6uw5yMHPAIgUXVRnpm1hFMVVOQ2FxwUpbIxBIfn8ORHM2BtQG+JPqHhuo0RuHBoQPSbaePEQNkUuGy51BkwfyuIpmpWQ1k11cCGGVeoJdme+7YBRmi6XIMl
NNTP-Posting-Date Sun, 30 Jan 2011 18:18:46 +0000 (UTC)
In-Reply-To <d4af9ddb-16e4-4e36-b22d-fb2a1ea125e3@f2g2000yqf.googlegroups.com>
Cancel-Lock sha1:Ykwue5TTbvuopNzt0/F3fwgGSUA=
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7
Injection-Info news.albasani.net; logging-data="CRAHOT2WCICqK/AL6N2pBOYrPRxdZ1RNUtA5quEx18dJynUJybM1qA+VxZLYuUeNGXI9qNlPT3+5B2Wqn1WWFEQZYUocDE1Ll6BSq+R+NGUiacWzdzxu2qsUOZzJh+nw"; mail-complaints-to="abuse@albasani.net"
Xref csiph.com comp.lang.java.programmer:26132

Show key headers only | 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 | Find similar | Unroll thread


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

csiph-web