Browse Source

Fix for handling Nullable types in JSON deserialization
re #328836

svn path=/trunk/mcs/; revision=87847

R. Tyler Ballance 18 years ago
parent
commit
407dc6bc3f

+ 12 - 0
mcs/class/System.Web.Extensions/System.Web.Script.Serialization/JavaScriptSerializer.cs

@@ -206,6 +206,18 @@ namespace System.Web.Script.Serialization
 			if (obj is IEnumerable<object>)
 			if (obj is IEnumerable<object>)
 				return ConvertToList ((IEnumerable<object>) obj, type);
 				return ConvertToList ((IEnumerable<object>) obj, type);
 
 
+			/*
+			 * Take care of the special case whereas in JSON an empty string ("") really means 
+			 * an empty value 
+			 * (see: https://bugzilla.novell.com/show_bug.cgi?id=328836)
+			 */
+			if ( (type.IsGenericType) && (type.GetGenericTypeDefinition() == typeof(Nullable<>)) )
+			{
+				string s = obj as String;
+				if (String.IsNullOrEmpty(s))
+						return null;
+			}
+
 			if (type == null)
 			if (type == null)
 				return obj;
 				return obj;