File tree Expand file tree Collapse file tree 4 files changed +67
-1
lines changed
main/java/io/kubernetes/client/util
java/io/kubernetes/client/util Expand file tree Collapse file tree 4 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -360,7 +360,12 @@ protected NodeTuple representJavaBeanProperty(
360
360
}
361
361
362
362
/** @return An instantiated SnakeYaml Object. */
363
- public static org .yaml .snakeyaml .Yaml getSnakeYaml (Class <?> type ) {
363
+ @ Deprecated
364
+ public static org .yaml .snakeyaml .Yaml getSnakeYaml () {
365
+ return getSnakeYaml (null );
366
+ }
367
+
368
+ private static org .yaml .snakeyaml .Yaml getSnakeYaml (Class <?> type ) {
364
369
if (type != null ) {
365
370
return new org .yaml .snakeyaml .Yaml (new CustomConstructor (type ), new CustomRepresenter ());
366
371
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2020 The Kubernetes Authors.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ package io .kubernetes .client .util ;
14
+
15
+ public class TestPoJ {
16
+ private static boolean marker = false ;
17
+
18
+ public TestPoJ () {
19
+ marker = true ;
20
+ }
21
+
22
+ public static boolean hasBeenConstructed () {
23
+ return marker ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ public class YamlTest {
47
47
48
48
private static final URL CREATED_TIMESTAMP_FILE = Resources .getResource ("test-pod.yaml" );
49
49
50
+ private static final URL TAGGED_FILE = Resources .getResource ("pod-tag.yaml" );
51
+
50
52
private static final String [] kinds =
51
53
new String [] {
52
54
"Pod" ,
@@ -256,4 +258,26 @@ public void testDateTimeRoundTrip() {
256
258
assertNull ("Unexpected exception: " + ex .toString (), ex );
257
259
}
258
260
}
261
+
262
+ @ Test
263
+ public void testYamlCantConstructObjects () {
264
+ try {
265
+ String data = Resources .toString (TAGGED_FILE , UTF_8 );
266
+ Object pod = Yaml .load (data );
267
+ } catch (Exception ex ) {
268
+ // pass
269
+ }
270
+ assertFalse ("Object should not be constructed!" , TestPoJ .hasBeenConstructed ());
271
+ }
272
+
273
+ @ Test
274
+ public void testLoadAsYamlCantConstructObjects () {
275
+ try {
276
+ String data = Resources .toString (TAGGED_FILE , UTF_8 );
277
+ V1Pod pod = Yaml .loadAs (data , V1Pod .class );
278
+ } catch (Exception ex ) {
279
+ // pass
280
+ }
281
+ assertFalse ("Object should not be constructed!" , TestPoJ .hasBeenConstructed ());
282
+ }
259
283
}
Original file line number Diff line number Diff line change
1
+ !!io.kubernetes.client.util.TestPoJ
2
+ apiVersion : v1
3
+ kind : Pod
4
+ metadata :
5
+ creationTimestamp : " 2018-12-23T01:09:18Z"
6
+ generateName : test-776d6c86cc-
7
+ labels :
8
+ app : test
9
+ app-version : " 19911"
10
+ pod-template-hash : " 3328274277"
11
+ name : test-776d6c86cc-4zwj5
12
+ namespace : default
You can’t perform that action at this time.
0 commit comments