Skip to content
Advertisement

Tag: xmlgregoriancalendar

Converting from Instant to XMLGregorianCalendar and vice-versa without losing precision

Using, java.time.Instant and javax.xml.datatype.XMLGregorianCalendar, I’m trying to convert from one to the other without losing precision. Why is this test not passing and how to fix it? Answer Why is this test not passing? Your XMLGregorianCalendar has got the full precision of your Instant. It’s your conversion back to Instant that is lossy. You are converting to GregorianCalendar through the

Jackson polymorphic serialization generates an incorrect class name

When I use Jackson polymorphic serialization, it generates a JSON object with an incorrect fully qualified class name. The code below serializes an XMLGregorianCalendar. The output is: I expected the following: Why does it output java.util.GregorianCalendar? Or more importantly: How do I fix this? Code example: Answer To get the expected behavior I have implemented a custom XMLGregorianCalendar serializer. This

java.util.Date to XMLGregorianCalendar

Isn’t there a convenient way of getting from a java.util.Date to a XMLGregorianCalendar? Answer I should like to take a step back and a modern look at this 10 years old question. The classes mentioned, Date and XMLGregorianCalendar, are old now. I challenge the use of them and offer alternatives. Date was always poorly designed and is more than 20

Advertisement