XStream vs XMLGregorianCalendar

Discussion in 'Java' started by bw, Jan 30, 2011.

  1. bw

    bw Guest

    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>?
    bw, Jan 30, 2011
    #1
    1. Advertising

  2. bw

    Arne Vajhøj Guest

    On 30-01-2011 04:18, bw wrote:
    > 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>?


    Are you using JAXB or XStream?

    Arne
    Arne Vajhøj, Jan 30, 2011
    #2
    1. Advertising

  3. bw

    Lew Guest

    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|
    |_____|_____|
    |===========|
    Lew, Jan 30, 2011
    #3
  4. bw

    Lew Guest

    Lew wrote:
    > (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]


    [1] Too often, we programmers disregard deployment and operations issues.
    It's a good exercise to figure out where to put your JAXB stuff in your
    version-control repository, write and run the build scripts (Ant, for example)
    that work off a clean export from that repository, accounting for code used on
    both ends of the exchange. Then deploy that yourself on two instances - one
    for each end - of whatever the target environments are (desktop app,
    smartphone app, Java EE app, ...). Integrate that with a
    continuous-integration platform like Hudson. For extra credit, put the
    database on a different host.

    That exercise tends to make you a fan of framework reduction - too many
    programmers take all the latest Springs and Ajax of outrageous configuration
    without regard for architecture, emergent interactions or transitive version
    dependencies. One outcome is to undo all the type safety of the Java
    language, substituting instead a mish-mosh of references by name whose
    incompatibilities come forward only at runtime.

    Injection has its place, but most of the time, what's wrong with just calling
    a durn method?

    --
    Lew
    Ceci n'est pas une fenêtre.
    ..___________.
    |###] | [###|
    |##/ | *\##|
    |#/ * | \#|
    |#----|----#|
    || | * ||
    |o * | o|
    |_____|_____|
    |===========|
    Lew, Jan 30, 2011
    #4
  5. bw

    Tom Anderson Guest

    On Sun, 30 Jan 2011, Lew wrote:

    > Domain objects can have muncher methods for schema graphs


    Is 'muncher method' a term with currency, or are you neologising? Either
    way, what does it mean?

    tom

    --
    Basically, at any given time, most people in the world are wasting time.
    Tom Anderson, Jan 30, 2011
    #5
  6. bw

    Tom Anderson Guest

    Tom Anderson, Jan 30, 2011
    #6
  7. bw

    Lew Guest

    On 01/30/2011 05:28 PM, Tom Anderson wrote:
    > On Sun, 30 Jan 2011, Lew wrote:
    >
    >> Domain objects can have muncher methods for schema graphs

    >
    > Is 'muncher method' a term with currency, or are you neologising? Either way,
    > what does it mean?


    It's a method that take schema graphs as arguments. It "munches" a schema and
    digests it into domain objects. No, it's not current - but it will be now!

    --
    Lew
    Ceci n'est pas une fenêtre.
    ..___________.
    |###] | [###|
    |##/ | *\##|
    |#/ * | \#|
    |#----|----#|
    || | * ||
    |o * | o|
    |_____|_____|
    |===========|
    Lew, Jan 31, 2011
    #7
  8. bw

    Lew Guest

    bw wrote:
    >> 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>?


    Tom Anderson wrote:
    > http://xstream.codehaus.org/converter-tutorial.html
    > http://download.oracle.com/javase/1...tatype/XMLGregorianCalendar.html#toXMLFormat()


    Absent a specific reason to do otherwise, it is best to avoid sending people
    to the API docs for an obsolete version of Java.

    http://download.oracle.com/javase/6...tatype/XMLGregorianCalendar.html#toXMLFormat()

    --
    Lew
    Ceci n'est pas une fenêtre.
    ..___________.
    |###] | [###|
    |##/ | *\##|
    |#/ * | \#|
    |#----|----#|
    || | * ||
    |o * | o|
    |_____|_____|
    |===========|
    Lew, Jan 31, 2011
    #8
  9. bw

    Tom Anderson Guest

    On Sun, 30 Jan 2011, Lew wrote:

    > bw wrote:
    >>> 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>?

    >
    > Tom Anderson wrote:
    >> http://xstream.codehaus.org/converter-tutorial.html
    >> http://download.oracle.com/javase/1...tatype/XMLGregorianCalendar.html#toXMLFormat()

    >
    > Absent a specific reason to do otherwise, it is best to avoid sending people
    > to the API docs for an obsolete version of Java.
    >
    > http://download.oracle.com/javase/6...tatype/XMLGregorianCalendar.html#toXMLFormat()


    Whoops! Too many tabs, not enough attention paid. Thanks for the
    correction.

    tom

    --
    Remember when we said there was no future? Well, this is it.
    Tom Anderson, Jan 31, 2011
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alain Frisch
    Replies:
    0
    Views:
    863
    Alain Frisch
    Jun 28, 2006
  2. Replies:
    1
    Views:
    32,641
    kgorthi
    Apr 16, 2009
  3. k3n85
    Replies:
    0
    Views:
    3,095
    k3n85
    Jul 15, 2009
  4. k3n85
    Replies:
    0
    Views:
    440
    k3n85
    Jul 15, 2009
  5. Daniel Pitts

    XStream and default field values.

    Daniel Pitts, Aug 16, 2010, in forum: Java
    Replies:
    2
    Views:
    2,190
    Daniel Pitts
    Aug 16, 2010
Loading...

Share This Page