0

I have a request described in xsd schema:

    <xs:element name="MyRequest">
        <xs:annotation>
            <xs:documentation>some documentation</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element name="MyList" type="test:MyType" minOccurs="1" maxOccurs="100">
                    <xs:annotation>
                        <xs:documentation>some documentation</xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

test:MyType has field of type xs:date:

<xs:element name="Birthday" type="xs:date" minOccurs="1" maxOccurs="1">
    <xs:annotation>
        <xs:documentation>date of birth/xs:documentation>
    </xs:annotation>
</xs:element>

which, when "translated" to Java class transforms into

@XmlElement(name = "Birthday", required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar birthday

but problem is that when request is sent it sends this parameter like this: <Birthday>1996-05-22Z</Birthday>

I know it's allowed per specification, but I was requested to send only date part : <Birthday>1996-05-22</Birthday> (without Z)

Is it possible without making Birhtday string and using SimpleDateFormat?

Sheyko Dmitriy
  • 383
  • 1
  • 3
  • 15
  • "`1996-05-22Z`" is nonsensical: what does "date in zulu time zone" mean? My birthday is the same, whatever time zone I travel to. Why do you need to send that? – Andy Turner Jul 16 '20 at 15:06
  • 1996-05-22Z means "the span of time from 1996-05-22 00:00 to 1996-05-22 23:59:59, both times in Zulu Time Zone". –  Jul 16 '20 at 15:12
  • 1
    I stand corrected that [such a date is allowed by the spec](https://www.w3.org/TR/xmlschema-2/#date); but I maintain that it's not meaningful to give a *birthday* (as opposed to some other date) in a time zone. – Andy Turner Jul 16 '20 at 15:51
  • I recommend you don’t use `SimpleDateFormat`. That class is notoriously troublesome and long outdated. If you end up wanting to use a formatter, use `DateTimeFormatter` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). You may also want just to use `LocalDate` from the same API. Its `toString` method produces `1996-05-22` format, guaranteed without `Z` or any other offset. – Ole V.V. Jul 16 '20 at 16:05
  • I can do that too (having a java gold badge). I just didn’t want to do it until you had confirmed, so I knew that I had understood the situation correctly. So thank you indeed for confirming. – Ole V.V. Jul 16 '20 at 17:00

0 Answers0