File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1818using System . Xml . Serialization ;
1919using Microsoft . VisualStudio . TestTools . UnitTesting ;
2020using Minio . DataModel ;
21+ using Minio . DataModel . Result ;
2122using Minio . Exceptions ;
2223using Minio . Helper ;
2324
@@ -235,4 +236,23 @@ public void TestisValidEndpoint()
235236 Assert . IsTrue ( RequestUtil . IsValidEndpoint ( "A.domain.com" ) ) ;
236237 Assert . IsTrue ( RequestUtil . IsValidEndpoint ( "A.domain1.com" ) ) ;
237238 }
239+
240+ [ TestMethod ]
241+ public void TestXmlResultWithoutNamespace ( )
242+ {
243+ var xml =
244+ """
245+ <?xml version="1.0" encoding="UTF-8"?>
246+ <CopyObjectResult>
247+ <LastModified>
248+ 2022-10-29T15:34:41.626Z
249+ </LastModified>
250+ <ETag>
251+ "ead3fcd881dee32547f1b6ca1fc29463"
252+ </ETag>
253+ </CopyObjectResult>
254+ """ ;
255+ var result = Utils . DeserializeXml < CopyObjectResult > ( xml ) ;
256+ Assert . IsNotNull ( result ) ;
257+ }
238258}
Original file line number Diff line number Diff line change @@ -24,5 +24,9 @@ public AmazonAwsS3XmlReader(Stream stream) : base(stream)
2424 {
2525 }
2626
27+ public AmazonAwsS3XmlReader ( TextReader textReader ) : base ( textReader )
28+ {
29+ }
30+
2731 public override string NamespaceURI => "http://s3.amazonaws.com/doc/2006-03-01/" ;
2832}
Original file line number Diff line number Diff line change @@ -1050,13 +1050,29 @@ public static string SerializeToXml<T>(T anyobject) where T : class
10501050 using var reader = new StreamReader ( stream ) ;
10511051 var xmlContent = reader . ReadToEnd ( ) ;
10521052
1053- return DeserializeXml < T > ( xmlContent ) ; // Call the string overload
1053+ return DeserializeNonS3Xml < T > ( xmlContent ) ; // Fallback to generic XML deserialization
10541054 }
10551055
10561056 public static T DeserializeXml < T > ( string xml ) where T : class , new ( )
10571057 {
10581058 if ( string . IsNullOrEmpty ( xml ) ) return default ;
10591059
1060+ var ns = GetNamespace < T > ( ) ;
1061+ if ( ! string . IsNullOrWhiteSpace ( ns ) && string . Equals ( ns , "http://s3.amazonaws.com/doc/2006-03-01/" ,
1062+ StringComparison . OrdinalIgnoreCase ) )
1063+ {
1064+ using var stringReader = new StringReader ( xml ) ;
1065+ using var amazonAwsS3XmlReader = new AmazonAwsS3XmlReader ( stringReader ) ;
1066+ return ( T ) new XmlSerializer ( typeof ( T ) ) . Deserialize ( amazonAwsS3XmlReader ) ;
1067+ }
1068+
1069+ return DeserializeNonS3Xml < T > ( xml ) ; // Fallback to generic XML deserialization
1070+ }
1071+
1072+ private static T DeserializeNonS3Xml < T > ( string xml ) where T : class , new ( )
1073+ {
1074+ if ( string . IsNullOrEmpty ( xml ) ) return default ;
1075+
10601076 var settings = new XmlReaderSettings
10611077 {
10621078 // Disable DTD processing
You can’t perform that action at this time.
0 commit comments