|
45 | 45 | public class CustomDateDeserializer extends StdDeserializer<Date> {
|
46 | 46 |
|
47 | 47 | /**
|
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. |
50 | 53 | */
|
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"),}; |
56 | 68 |
|
57 | 69 | /**
|
58 | 70 | * Constructs a {@link CustomDateDeserializer} instance.
|
@@ -80,10 +92,10 @@ public CustomDateDeserializer(Class t) {
|
80 | 92 | */
|
81 | 93 | @Override
|
82 | 94 | public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
83 |
| - |
| 95 | + var text = jsonParser.getText(); |
84 | 96 | for (SimpleDateFormat formatter : dateFormatters) {
|
85 | 97 | try {
|
86 |
| - return formatter.parse(jsonParser.getText()); |
| 98 | + return formatter.parse(text); |
87 | 99 | } catch (ParseException e) {
|
88 | 100 | // ignore
|
89 | 101 | }
|
|
0 commit comments