Skip to content

Commit a2a1080

Browse files
Extend Java deserialization support for xen-api dates
non-Zulu dates were not parsed correctly Signed-off-by: Danilo Del Busso <[email protected]>
1 parent b0e0bab commit a2a1080

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

ocaml/sdk-gen/java/autogen/xen-api/src/main/java/com/xensource/xenapi/CustomDateDeserializer.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,26 @@
4545
public class CustomDateDeserializer extends StdDeserializer<Date> {
4646

4747
/**
48-
* Array of {@link SimpleDateFormat} objects representing the custom date formats
49-
* used in XenServer API responses.
48+
* Array of {@link SimpleDateFormat} objects representing the date formats
49+
* used in xen-api responses.
50+
* RFC-3339 date formats can be returned in either Zulu or time zone agnostic.
51+
* This list is not an exhaustive list of formats supported by RFC-3339, rather
52+
* a set of formats that will enable the deserialization of xen-api dates.
5053
*/
51-
private final SimpleDateFormat[] dateFormatters
52-
= new SimpleDateFormat[]{
53-
new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss'Z'"),
54-
new SimpleDateFormat("ss.SSS")
55-
};
54+
private final SimpleDateFormat[] dateFormatters = new SimpleDateFormat[]{
55+
// RFC-3339
56+
new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss'Z'"), new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"),
57+
58+
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"),
59+
60+
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"),
61+
62+
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"),
63+
64+
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"),
65+
66+
// Other
67+
new SimpleDateFormat("ss.SSS"),};
5668

5769
/**
5870
* Constructs a {@link CustomDateDeserializer} instance.
@@ -80,10 +92,10 @@ public CustomDateDeserializer(Class t) {
8092
*/
8193
@Override
8294
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
83-
95+
var text = jsonParser.getText();
8496
for (SimpleDateFormat formatter : dateFormatters) {
8597
try {
86-
return formatter.parse(jsonParser.getText());
98+
return formatter.parse(text);
8799
} catch (ParseException e) {
88100
// ignore
89101
}

0 commit comments

Comments
 (0)