File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
main/java/io/kubernetes/client/util
java/io/kubernetes/client/util Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,14 @@ public CustomRepresenter() {
358
358
this .representers .put (IntOrString .class , new RepresentIntOrString ());
359
359
this .representers .put (byte [].class , new RepresentByteArray ());
360
360
this .representers .put (Quantity .class , new RepresentQuantity ());
361
+ this .representers .put (DateTime .class , new RepresentDateTime ());
362
+ }
363
+
364
+ private class RepresentDateTime implements Represent {
365
+ @ Override
366
+ public Node representData (Object data ) {
367
+ return CustomRepresenter .this .representData (data .toString ());
368
+ }
361
369
}
362
370
363
371
private class RepresentIntOrString implements Represent {
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ public class YamlTest {
43
43
44
44
private static final URL EXPECTED_YAML_FILE = Resources .getResource ("expected.yaml" );
45
45
46
+ private static final URL CREATED_TIMESTAMP_FILE = Resources .getResource ("test-pod.yaml" );
47
+
46
48
private static final String [] kinds =
47
49
new String [] {
48
50
"Pod" ,
@@ -236,4 +238,19 @@ public void testDateTime() {
236
238
assertNull ("Unexpected exception: " + ex .toString (), ex );
237
239
}
238
240
}
241
+
242
+ @ Test
243
+ public void testDateTimeRoundTrip () {
244
+ // There was an issue with dumping JODA DateTime as String.
245
+ // This test verifies that its fixed.
246
+ try {
247
+ String data = Resources .toString (CREATED_TIMESTAMP_FILE , UTF_8 );
248
+ V1Pod pod = Yaml .loadAs (data , V1Pod .class );
249
+ String output = Yaml .dump (pod );
250
+ V1Pod pod2 = Yaml .loadAs (output , V1Pod .class );
251
+ assertEquals (pod , pod2 );
252
+ } catch (Exception ex ) {
253
+ assertNull ("Unexpected exception: " + ex .toString (), ex );
254
+ }
255
+ }
239
256
}
Original file line number Diff line number Diff line change
1
+ apiVersion : v1
2
+ kind : Pod
3
+ metadata :
4
+ creationTimestamp : " 2018-12-23T01:09:18Z"
5
+ generateName : test-776d6c86cc-
6
+ labels :
7
+ app : test
8
+ app-version : " 19911"
9
+ pod-template-hash : " 3328274277"
10
+ name : test-776d6c86cc-4zwj5
11
+ namespace : default
You can’t perform that action at this time.
0 commit comments