|
Replies:
9
-
Last Post:
Oct 24, 2006 5:06 PM
by: kohsuke
|
|
|
|
|
|
|
Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 13, 2006 12:10 PM
|
|
|
Does anyone know why JAX-WS uses XMLGregorianCalendar for Date values on the client side? Why not just use Date instead? I can see why it would use it internally, but, I can't see why the client should have to use something XML specific. The Java Calendar and Date classes seem unnecessarily complicated to begin with and XMLGregorianCalendar is even worse. From what I know so far, there isn't even a way to initialize an XMLGregorianCalendar from a Date in one step. i.e. There's no setTime() method. You have to set the fields individually which seems rather unnecessary.
.NET just uses the standard DateTime class. I don't know why things have to be more complicated in the Java world.
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 13, 2006 12:20 PM
in response to: jemiller1
|
|
|
I just noticed that you can use DatatypeFactory to create an XMLGregorianCalendar and set it to a GregorianCalendar. What's the point of having a separate factory?
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 14, 2006 7:23 AM
in response to: jemiller1
|
|
|
XMLGregorianCalendar is thought to be necessary because Java's standard Date/Calendar types cannot represent all the possible values allowed in XML Schema date-related types. Such difference is often small --- for example, whether you can correctly represent 0.0001sec, or year 9999999999999, etc. So I kind of agree that it was a poor choice to make that a default.
Then there's a fact that XMLGregorianCalendar is awfully hard to use. The factory class, as you pointed out, then the checked exception it throws. There are a few RFEs filed around this, so it should become better in the next revision of JAXP.
The good news is that you can tell JAXB to use Calendar instead of XMLGregorianCalendar. Check the archive with XMLGregorianCalendar and you'll find how.
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 16, 2006 4:58 AM
in response to: kohsuke
|
|
|
> The good news is that you can tell JAXB to use > Calendar instead of XMLGregorianCalendar. Check the > archive with XMLGregorianCalendar and you'll find how.
Alternatively, use a binding customisation which binds the XSD types to JodaTime types. Much, much nicer to use than XmlGregorianCalendar and GregorianCalendar.
http://joda-time.sourceforge.net/
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 16, 2006 3:17 PM
in response to: kohsuke
|
|
|
Hehe, thanks. Yeah, after I wrote this, I noticed that it threw a checked exception. I was grumbling about that to myself and my boss. That's good to know that you can configure the data type. I'll look into that.
On an unrelated note, is the forum supposed to notify you when someone posts a reply and you've selected to watch the post? Maybe it's my spam filters...
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 16, 2006 4:48 PM
in response to: jemiller1
|
|
|
Another person reported the same issue. I'll forward your comment to admin.
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 21, 2006 9:07 PM
in response to: kohsuke
|
|
|
I just ran into this same thing, my Date fields on the server end up as XMLGregorianCalendar on the client. Foir something so common as Date, I'm surprised that JAX-WS would do something like this.
Is there any way to make it use java.util.Date in some config or annotation?
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 23, 2006 10:24 AM
in response to: kohsuke
|
|
|
Yes, I know you can customize it, but if my objects have java.util.Date when running wsgen, wouldn't it be reasonable to expect wsgen would take care of that for me? Or am I missing something?
|
|
|
|
|
|
|
|
Re: Why does the JAX-WS client code use XMLGregorianCalendar?
Posted:
Oct 24, 2006 5:06 PM
in response to: prophecy
|
|
|
I think it's not necessarily desirable for there to be such strong tie between how the server is written and how the client is written, so it's hard to say.
Providing such an option in wsgen would certainly be an excellent idea.
|
|
|
|
|