1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -77,7 +77,8 @@ public TemporalAccessorParser(Class<? extends TemporalAccessor> temporalAccessor
77
77
}
78
78
79
79
TemporalAccessorParser (Class <? extends TemporalAccessor > temporalAccessorType , DateTimeFormatter formatter ,
80
- @ Nullable String [] fallbackPatterns , @ Nullable Object source ) {
80
+ @ Nullable String [] fallbackPatterns , @ Nullable Object source ) {
81
+
81
82
this .temporalAccessorType = temporalAccessorType ;
82
83
this .formatter = formatter ;
83
84
this .fallbackPatterns = fallbackPatterns ;
@@ -104,10 +105,19 @@ public TemporalAccessor parse(String text, Locale locale) throws ParseException
104
105
}
105
106
}
106
107
}
108
+ else {
109
+ // Fallback to ISO-based default java.time type parsing
110
+ try {
111
+ return defaultParse (text );
112
+ }
113
+ catch (DateTimeParseException ignoredException ) {
114
+ // Ignore fallback parsing exception like above
115
+ }
116
+ }
107
117
if (this .source != null ) {
108
118
throw new DateTimeParseException (
109
- String .format ("Unable to parse date time value \" %s\" using configuration from %s" , text , this .source ),
110
- text , ex .getErrorIndex (), ex );
119
+ String .format ("Unable to parse date time value \" %s\" using configuration from %s" , text , this .source ),
120
+ text , ex .getErrorIndex (), ex );
111
121
}
112
122
// else rethrow original exception
113
123
throw ex ;
@@ -148,4 +158,37 @@ else if (MonthDay.class == this.temporalAccessorType) {
148
158
}
149
159
}
150
160
161
+ private TemporalAccessor defaultParse (String text ) throws DateTimeParseException {
162
+ if (Instant .class == this .temporalAccessorType ) {
163
+ return Instant .parse (text );
164
+ }
165
+ else if (LocalDate .class == this .temporalAccessorType ) {
166
+ return LocalDate .parse (text );
167
+ }
168
+ else if (LocalTime .class == this .temporalAccessorType ) {
169
+ return LocalTime .parse (text );
170
+ }
171
+ else if (LocalDateTime .class == this .temporalAccessorType ) {
172
+ return LocalDateTime .parse (text );
173
+ }
174
+ else if (ZonedDateTime .class == this .temporalAccessorType ) {
175
+ return ZonedDateTime .parse (text );
176
+ }
177
+ else if (OffsetDateTime .class == this .temporalAccessorType ) {
178
+ return OffsetDateTime .parse (text );
179
+ }
180
+ else if (OffsetTime .class == this .temporalAccessorType ) {
181
+ return OffsetTime .parse (text );
182
+ }
183
+ else if (YearMonth .class == this .temporalAccessorType ) {
184
+ return YearMonth .parse (text );
185
+ }
186
+ else if (MonthDay .class == this .temporalAccessorType ) {
187
+ return MonthDay .parse (text );
188
+ }
189
+ else {
190
+ throw new IllegalStateException ("Unsupported TemporalAccessor type: " + this .temporalAccessorType );
191
+ }
192
+ }
193
+
151
194
}
0 commit comments