tag:blogger.com,1999:blog-1710464868724994296.post1771901378629642267..comments2023-06-29T09:48:09.653-04:00Comments on Java XML and JSON Binding: JAXB and Joda-Time: Dates and TimesBlaise Doughanhttp://www.blogger.com/profile/02016807982653343777noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-1710464868724994296.post-56245778810267227912013-08-31T18:03:20.448-04:002013-08-31T18:03:20.448-04:00Excelled article!
May be worthwhile to note to pre...Excelled article!<br />May be worthwhile to note to prevent WTF moments:<br />1. you can put the above classes to ANY package you like, e.g. com.mycompany.utils.jaxb<br />2. you MUST create a file from "Registering the XmlAdapters" section named "package-info.java" in the package where you want to USE the adapter utility classes<br />3. you have to define package-info.java in EACH and EVERY package you want to use, not inherited.<br />(Fix the imports of course)TWiStErRobhttps://www.blogger.com/profile/06796806062682950121noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-27639808977515570092013-02-20T10:23:23.855-05:002013-02-20T10:23:23.855-05:00Excellent example. work well on my domain package ...Excellent example. work well on my domain package to serialized my object using JodaTimeAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-51784567619128142842012-02-11T10:02:17.695-05:002012-02-11T10:02:17.695-05:00Thank you man. Big time saverThank you man. Big time saverFabrício Lemosnoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-76045678448683263952012-01-20T12:51:46.538-05:002012-01-20T12:51:46.538-05:00I believe part of your question has been lost due ...I believe part of your question has been lost due to the formatting restrictions of the comment area. You may find the following post useful:<br />- <a href="http://blog.bdoughan.com/2011/08/xml-schema-to-java-generating.html" rel="nofollow">XML Schema to Java - Generating XmlAdapters</a><br /><br />Feel free to send me a note through my contact page:<br />- <a href="http://blog.bdoughan.com/p/contact_01.html" rel="nofollow">Contact Me</a><br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-23795171067781557832012-01-11T08:39:55.961-05:002012-01-11T08:39:55.961-05:00When using DateTime how would I set up this in my ...When using DateTime how would I set up this in my schema?<br /><br />I have used the following type with XMLGregorianCalendar:Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-27499455368768963992011-08-21T18:26:24.329-04:002011-08-21T18:26:24.329-04:00Hi Blaise
Thanks for the useful post, I didn'...Hi Blaise <br /><br />Thanks for the useful post, I didn't realize that joda was using the correct ISO standard by default! <br /><br />One minor note though - the sources for XmlAdapter say that they 'value' in the marshal/unmarshal methods can be null, so the converter should cleanly handle those situations, otherwise you may get some NullPointerExceptions.<br /><br />Also, the LocalDateTimeAdapter will fail to parse a string that contains a timezone (with an error message like this: Invalid format: "2001-10-26T21:32:52+02:00" is malformed at "+02:00"). I've modified my sources to first use a DateTime instance, <br /><br />if (dateTime == null) {return null;}<br />return new DateTime(dateTime).toLocalDateTime();<br /><br />instead of <br /><br />return new LocalDateTime(dateTime);Barry Pitmanhttps://www.blogger.com/profile/11494038686679214751noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-25567085438790995842011-07-20T16:50:07.883-04:002011-07-20T16:50:07.883-04:00Hi Collin,
This behaviour will vary between JAXB ...Hi Collin,<br /><br />This behaviour will vary between JAXB implementations. <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow">EclipseLink JAXB (MOXy)</a> for example will throw a conversion exception.<br /><br />I gave a slightly more detailed answer to a similar question on Stack Overflow:<br />- <a href="http://stackoverflow.com/questions/6689023/jaxb-binding-xmlgregoriancalendar/6694413#6694413" rel="nofollow">JaxB binding XMLGregorianCalendar</a><br /><br />-BlaiseBlaise Doughanhttps://www.blogger.com/profile/02016807982653343777noreply@blogger.comtag:blogger.com,1999:blog-1710464868724994296.post-57001656768762174332011-07-19T16:04:38.673-04:002011-07-19T16:04:38.673-04:00How do you handle exceptions with this? I have a L...How do you handle exceptions with this? I have a LocalDate birthdate field and when I send '1980x-01-2' it just seems to absorb the exception and leave the field nullCollin Petershttps://www.blogger.com/profile/17888430560901277301noreply@blogger.com