28
28
import java .util .ArrayList ;
29
29
import java .util .Arrays ;
30
30
import java .util .Collection ;
31
- import java .util .Collections ;
32
31
import java .util .List ;
33
32
34
33
import org .springframework .core .convert .converter .Converter ;
35
- import org .springframework .data .convert .ReadingConverter ;
36
- import org .springframework .data .convert .WritingConverter ;
37
34
import org .springframework .data .redis .core .convert .BinaryConverters .StringBasedConverter ;
38
- import org .springframework .util .ClassUtils ;
39
35
40
36
/**
41
- * Helper class to register JSR-310 specific {@link Converter} implementations in case the we're running on Java 8 .
37
+ * Helper class to register JSR-310 specific {@link Converter} implementations.
42
38
*
43
39
* @author Mark Paluch
40
+ * @author John Blum
44
41
*/
45
42
public abstract class Jsr310Converters {
46
43
47
- private static final boolean JAVA_8_IS_PRESENT = ClassUtils .isPresent ("java.time.LocalDateTime" ,
48
- Jsr310Converters .class .getClassLoader ());
49
-
50
44
/**
51
45
* Returns the {@link Converter Converters} to be registered.
52
- * <p>
53
- * Will only return {@link Converter Converters} in case we're running on Java 8.
54
46
*
55
47
* @return the {@link Converter Converters} to be registered.
56
48
*/
57
49
public static Collection <Converter <?, ?>> getConvertersToRegister () {
58
50
59
- if (!JAVA_8_IS_PRESENT ) {
60
- return Collections .emptySet ();
61
- }
62
-
63
- List <Converter <?, ?>> converters = new ArrayList <>();
51
+ List <Converter <?, ?>> converters = new ArrayList <>(20 );
64
52
65
53
converters .add (new LocalDateTimeToBytesConverter ());
66
54
converters .add (new BytesToLocalDateTimeConverter ());
@@ -88,19 +76,15 @@ public abstract class Jsr310Converters {
88
76
89
77
public static boolean supports (Class <?> type ) {
90
78
91
- if (!JAVA_8_IS_PRESENT ) {
92
- return false ;
93
- }
94
-
95
79
return Arrays .<Class <?>> asList (LocalDateTime .class , LocalDate .class , LocalTime .class , Instant .class ,
96
- ZonedDateTime .class , ZoneId .class , Period .class , Duration .class ).contains (type );
80
+ ZonedDateTime .class , ZoneId .class , Period .class , Duration .class , OffsetDateTime .class , OffsetTime .class )
81
+ .contains (type );
97
82
}
98
83
99
84
/**
100
85
* @author Mark Paluch
101
86
* @since 1.7
102
87
*/
103
- @ WritingConverter
104
88
static class LocalDateTimeToBytesConverter extends StringBasedConverter implements Converter <LocalDateTime , byte []> {
105
89
106
90
@ Override
@@ -113,7 +97,6 @@ public byte[] convert(LocalDateTime source) {
113
97
* @author Mark Paluch
114
98
* @since 1.7
115
99
*/
116
- @ ReadingConverter
117
100
static class BytesToLocalDateTimeConverter extends StringBasedConverter implements Converter <byte [], LocalDateTime > {
118
101
119
102
@ Override
@@ -126,7 +109,6 @@ public LocalDateTime convert(byte[] source) {
126
109
* @author Mark Paluch
127
110
* @since 1.7
128
111
*/
129
- @ WritingConverter
130
112
static class LocalDateToBytesConverter extends StringBasedConverter implements Converter <LocalDate , byte []> {
131
113
132
114
@ Override
@@ -139,7 +121,6 @@ public byte[] convert(LocalDate source) {
139
121
* @author Mark Paluch
140
122
* @since 1.7
141
123
*/
142
- @ ReadingConverter
143
124
static class BytesToLocalDateConverter extends StringBasedConverter implements Converter <byte [], LocalDate > {
144
125
145
126
@ Override
@@ -152,7 +133,6 @@ public LocalDate convert(byte[] source) {
152
133
* @author Mark Paluch
153
134
* @since 1.7
154
135
*/
155
- @ WritingConverter
156
136
static class LocalTimeToBytesConverter extends StringBasedConverter implements Converter <LocalTime , byte []> {
157
137
158
138
@ Override
@@ -165,7 +145,6 @@ public byte[] convert(LocalTime source) {
165
145
* @author Mark Paluch
166
146
* @since 1.7
167
147
*/
168
- @ ReadingConverter
169
148
static class BytesToLocalTimeConverter extends StringBasedConverter implements Converter <byte [], LocalTime > {
170
149
171
150
@ Override
@@ -178,7 +157,6 @@ public LocalTime convert(byte[] source) {
178
157
* @author Mark Paluch
179
158
* @since 1.7
180
159
*/
181
- @ WritingConverter
182
160
static class ZonedDateTimeToBytesConverter extends StringBasedConverter implements Converter <ZonedDateTime , byte []> {
183
161
184
162
@ Override
@@ -191,7 +169,6 @@ public byte[] convert(ZonedDateTime source) {
191
169
* @author Mark Paluch
192
170
* @since 1.7
193
171
*/
194
- @ ReadingConverter
195
172
static class BytesToZonedDateTimeConverter extends StringBasedConverter implements Converter <byte [], ZonedDateTime > {
196
173
197
174
@ Override
@@ -204,7 +181,6 @@ public ZonedDateTime convert(byte[] source) {
204
181
* @author Mark Paluch
205
182
* @since 1.7
206
183
*/
207
- @ WritingConverter
208
184
static class InstantToBytesConverter extends StringBasedConverter implements Converter <Instant , byte []> {
209
185
210
186
@ Override
@@ -217,7 +193,6 @@ public byte[] convert(Instant source) {
217
193
* @author Mark Paluch
218
194
* @since 1.7
219
195
*/
220
- @ ReadingConverter
221
196
static class BytesToInstantConverter extends StringBasedConverter implements Converter <byte [], Instant > {
222
197
223
198
@ Override
@@ -230,7 +205,6 @@ public Instant convert(byte[] source) {
230
205
* @author Mark Paluch
231
206
* @since 1.7
232
207
*/
233
- @ WritingConverter
234
208
static class ZoneIdToBytesConverter extends StringBasedConverter implements Converter <ZoneId , byte []> {
235
209
236
210
@ Override
@@ -243,7 +217,6 @@ public byte[] convert(ZoneId source) {
243
217
* @author Mark Paluch
244
218
* @since 1.7
245
219
*/
246
- @ ReadingConverter
247
220
static class BytesToZoneIdConverter extends StringBasedConverter implements Converter <byte [], ZoneId > {
248
221
249
222
@ Override
@@ -256,7 +229,6 @@ public ZoneId convert(byte[] source) {
256
229
* @author Mark Paluch
257
230
* @since 1.7
258
231
*/
259
- @ WritingConverter
260
232
static class PeriodToBytesConverter extends StringBasedConverter implements Converter <Period , byte []> {
261
233
262
234
@ Override
@@ -269,7 +241,6 @@ public byte[] convert(Period source) {
269
241
* @author Mark Paluch
270
242
* @since 1.7
271
243
*/
272
- @ ReadingConverter
273
244
static class BytesToPeriodConverter extends StringBasedConverter implements Converter <byte [], Period > {
274
245
275
246
@ Override
@@ -282,7 +253,6 @@ public Period convert(byte[] source) {
282
253
* @author Mark Paluch
283
254
* @since 1.7
284
255
*/
285
- @ WritingConverter
286
256
static class DurationToBytesConverter extends StringBasedConverter implements Converter <Duration , byte []> {
287
257
288
258
@ Override
@@ -295,7 +265,6 @@ public byte[] convert(Duration source) {
295
265
* @author Mark Paluch
296
266
* @since 1.7
297
267
*/
298
- @ ReadingConverter
299
268
static class BytesToDurationConverter extends StringBasedConverter implements Converter <byte [], Duration > {
300
269
301
270
@ Override
@@ -306,9 +275,10 @@ public Duration convert(byte[] source) {
306
275
307
276
/**
308
277
* @author John Blum
309
- * @see java.time.OffsetDateTime
278
+ * @since 3.0.9
310
279
*/
311
- static class OffsetDateTimeToBytesConverter extends StringBasedConverter implements Converter <OffsetDateTime , byte []> {
280
+ static class OffsetDateTimeToBytesConverter extends StringBasedConverter
281
+ implements Converter <OffsetDateTime , byte []> {
312
282
313
283
@ Override
314
284
public byte [] convert (OffsetDateTime source ) {
@@ -318,9 +288,10 @@ public byte[] convert(OffsetDateTime source) {
318
288
319
289
/**
320
290
* @author John Blum
321
- * @see java.time.OffsetDateTime
291
+ * @since 3.0.9
322
292
*/
323
- static class BytesToOffsetDateTimeConverter extends StringBasedConverter implements Converter <byte [], OffsetDateTime > {
293
+ static class BytesToOffsetDateTimeConverter extends StringBasedConverter
294
+ implements Converter <byte [], OffsetDateTime > {
324
295
325
296
@ Override
326
297
public OffsetDateTime convert (byte [] source ) {
@@ -330,7 +301,7 @@ public OffsetDateTime convert(byte[] source) {
330
301
331
302
/**
332
303
* @author John Blum
333
- * @see java.time.OffsetTime
304
+ * @since 3.0.9
334
305
*/
335
306
static class OffsetTimeToBytesConverter extends StringBasedConverter implements Converter <OffsetTime , byte []> {
336
307
@@ -342,7 +313,7 @@ public byte[] convert(OffsetTime source) {
342
313
343
314
/**
344
315
* @author John Blum
345
- * @see java.time.OffsetTime
316
+ * @since 3.0.9
346
317
*/
347
318
static class BytesToOffsetTimeConverter extends StringBasedConverter implements Converter <byte [], OffsetTime > {
348
319
0 commit comments