@@ -629,10 +629,19 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
629629 */
630630 public static Object createResource (io .kubernetes .client .openapi .ApiClient client , Reader reader )
631631 throws IOException , io .kubernetes .client .openapi .ApiException {
632+ // Read the entire content into a string first so we can parse it twice
633+ StringBuilder sb = new StringBuilder ();
634+ char [] buffer = new char [8192 ];
635+ int read ;
636+ while ((read = reader .read (buffer )) != -1 ) {
637+ sb .append (buffer , 0 , read );
638+ }
639+ String yamlContent = sb .toString ();
640+
632641 // Load the YAML as a map to extract apiVersion and kind
633642 // Note: The getSnakeYaml() method already configures LoaderOptions with appropriate
634643 // security settings to prevent YAML bombs and other attacks
635- Map <String , Object > data = getSnakeYaml (null ).load (reader );
644+ Map <String , Object > data = getSnakeYaml (null ).load (new StringReader ( yamlContent ) );
636645
637646 String kind = (String ) data .get ("kind" );
638647 if (kind == null ) {
@@ -650,10 +659,8 @@ public static Object createResource(io.kubernetes.client.openapi.ApiClient clien
650659 "Unknown apiVersion/kind: " + apiVersion + "/" + kind + ". Is it registered?" );
651660 }
652661
653- // Load the YAML into the strongly typed object
654- // Note: This double-loading approach (first as Map, then as typed object) follows the
655- // design recommended in the issue discussion to properly handle type determination
656- Object resource = loadAs (new StringReader (getSnakeYaml (clazz ).dump (data )), clazz );
662+ // Load the YAML into the strongly typed object using the same content
663+ Object resource = loadAs (new StringReader (yamlContent ), clazz );
657664
658665 // Ensure the resource is a KubernetesObject
659666 if (!(resource instanceof io .kubernetes .client .common .KubernetesObject )) {
0 commit comments