10
10
* Do not edit the class manually.
11
11
*/
12
12
13
-
14
13
package io .kubernetes .client ;
15
14
16
15
import com .google .gson .Gson ;
20
19
import com .google .gson .internal .bind .util .ISO8601Utils ;
21
20
import com .google .gson .stream .JsonReader ;
22
21
import com .google .gson .stream .JsonWriter ;
22
+
23
+ import okio .ByteString ;
24
+
23
25
import org .joda .time .DateTime ;
24
26
import org .joda .time .LocalDate ;
25
27
import org .joda .time .format .DateTimeFormatter ;
@@ -41,13 +43,15 @@ public class JSON {
41
43
private SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter ();
42
44
private DateTimeTypeAdapter dateTimeTypeAdapter = new DateTimeTypeAdapter ();
43
45
private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter ();
46
+ private ByteArrayAdapter byteArrayTypeAdapter = new ByteArrayAdapter ();
44
47
45
48
public JSON () {
46
49
gson = new GsonBuilder ()
47
50
.registerTypeAdapter (Date .class , dateTypeAdapter )
48
51
.registerTypeAdapter (java .sql .Date .class , sqlDateTypeAdapter )
49
52
.registerTypeAdapter (DateTime .class , dateTimeTypeAdapter )
50
53
.registerTypeAdapter (LocalDate .class , localDateTypeAdapter )
54
+ .registerTypeAdapter (byte [].class , byteArrayTypeAdapter )
51
55
.create ();
52
56
}
53
57
@@ -110,7 +114,36 @@ public <T> T deserialize(String body, Type returnType) {
110
114
// return the response body string directly for the String return type;
111
115
if (returnType .equals (String .class ))
112
116
return (T ) body ;
113
- else throw (e );
117
+ else
118
+ throw (e );
119
+ }
120
+ }
121
+
122
+ /**
123
+ + * Gson TypeAdapter for Byte Array type
124
+ + */
125
+ public class ByteArrayAdapter extends TypeAdapter <byte []> {
126
+
127
+ @ Override
128
+ public void write (JsonWriter out , byte [] value ) throws IOException {
129
+ if (value == null ) {
130
+ out .nullValue ();
131
+ } else {
132
+ out .value (ByteString .of (value ).base64 ());
133
+ }
134
+ }
135
+
136
+ @ Override
137
+ public byte [] read (JsonReader in ) throws IOException {
138
+ switch (in .peek ()) {
139
+ case NULL :
140
+ in .nextNull ();
141
+ return null ;
142
+ default :
143
+ String bytesAsBase64 = in .nextString ();
144
+ ByteString byteString = ByteString .decodeBase64 (bytesAsBase64 );
145
+ return byteString .toByteArray ();
146
+ }
114
147
}
115
148
}
116
149
@@ -122,9 +155,8 @@ public static class DateTimeTypeAdapter extends TypeAdapter<DateTime> {
122
155
private DateTimeFormatter formatter ;
123
156
124
157
public DateTimeTypeAdapter () {
125
- this (new DateTimeFormatterBuilder ()
126
- .append (ISODateTimeFormat .dateTime ().getPrinter (), ISODateTimeFormat .dateOptionalTimeParser ().getParser ())
127
- .toFormatter ());
158
+ this (new DateTimeFormatterBuilder ().append (ISODateTimeFormat .dateTime ().getPrinter (),
159
+ ISODateTimeFormat .dateOptionalTimeParser ().getParser ()).toFormatter ());
128
160
}
129
161
130
162
public DateTimeTypeAdapter (DateTimeFormatter formatter ) {
@@ -147,12 +179,12 @@ public void write(JsonWriter out, DateTime date) throws IOException {
147
179
@ Override
148
180
public DateTime read (JsonReader in ) throws IOException {
149
181
switch (in .peek ()) {
150
- case NULL :
151
- in .nextNull ();
152
- return null ;
153
- default :
154
- String date = in .nextString ();
155
- return formatter .parseDateTime (date );
182
+ case NULL :
183
+ in .nextNull ();
184
+ return null ;
185
+ default :
186
+ String date = in .nextString ();
187
+ return formatter .parseDateTime (date );
156
188
}
157
189
}
158
190
}
@@ -188,12 +220,12 @@ public void write(JsonWriter out, LocalDate date) throws IOException {
188
220
@ Override
189
221
public LocalDate read (JsonReader in ) throws IOException {
190
222
switch (in .peek ()) {
191
- case NULL :
192
- in .nextNull ();
193
- return null ;
194
- default :
195
- String date = in .nextString ();
196
- return formatter .parseLocalDate (date );
223
+ case NULL :
224
+ in .nextNull ();
225
+ return null ;
226
+ default :
227
+ String date = in .nextString ();
228
+ return formatter .parseLocalDate (date );
197
229
}
198
230
}
199
231
}
@@ -246,19 +278,19 @@ public void write(JsonWriter out, java.sql.Date date) throws IOException {
246
278
@ Override
247
279
public java .sql .Date read (JsonReader in ) throws IOException {
248
280
switch (in .peek ()) {
249
- case NULL :
250
- in .nextNull ();
251
- return null ;
252
- default :
253
- String date = in .nextString ();
254
- try {
255
- if (dateFormat != null ) {
256
- return new java .sql .Date (dateFormat .parse (date ).getTime ());
257
- }
258
- return new java .sql .Date (ISO8601Utils .parse (date , new ParsePosition (0 )).getTime ());
259
- } catch (ParseException e ) {
260
- throw new JsonParseException (e );
281
+ case NULL :
282
+ in .nextNull ();
283
+ return null ;
284
+ default :
285
+ String date = in .nextString ();
286
+ try {
287
+ if (dateFormat != null ) {
288
+ return new java .sql .Date (dateFormat .parse (date ).getTime ());
261
289
}
290
+ return new java .sql .Date (ISO8601Utils .parse (date , new ParsePosition (0 )).getTime ());
291
+ } catch (ParseException e ) {
292
+ throw new JsonParseException (e );
293
+ }
262
294
}
263
295
}
264
296
}
@@ -301,19 +333,19 @@ public void write(JsonWriter out, Date date) throws IOException {
301
333
public Date read (JsonReader in ) throws IOException {
302
334
try {
303
335
switch (in .peek ()) {
304
- case NULL :
305
- in .nextNull ();
306
- return null ;
307
- default :
308
- String date = in .nextString ();
309
- try {
310
- if (dateFormat != null ) {
311
- return dateFormat .parse (date );
312
- }
313
- return ISO8601Utils .parse (date , new ParsePosition (0 ));
314
- } catch (ParseException e ) {
315
- throw new JsonParseException (e );
336
+ case NULL :
337
+ in .nextNull ();
338
+ return null ;
339
+ default :
340
+ String date = in .nextString ();
341
+ try {
342
+ if (dateFormat != null ) {
343
+ return dateFormat .parse (date );
316
344
}
345
+ return ISO8601Utils .parse (date , new ParsePosition (0 ));
346
+ } catch (ParseException e ) {
347
+ throw new JsonParseException (e );
348
+ }
317
349
}
318
350
} catch (IllegalArgumentException e ) {
319
351
throw new JsonParseException (e );
0 commit comments