Permalink
Browse files

Fixing setting of null value types. Fixes #18.

  • Loading branch information...
1 parent 77114e7 commit 3fa7bc397b8e3df9c484ab63123bd1950c4036f4 @mckamey mckamey committed Sep 28, 2012
@@ -3,7 +3,7 @@
<metadata>
<id>JsonFx</id>
<title>JsonFx</title>
- <version>2.0.1209.2801</version>
+ <version>2.0.1209.2802</version>
<authors>Stephen McKamey</authors>
<owners>mckamey</owners>
<licenseUrl>https://raw.github.com/jsonfx/jsonfx/master/LICENSE.txt</licenseUrl>
@@ -335,16 +335,37 @@ public void Read_DeserializesStreamOfObject()
.GetResponse()
.GetResponseStream())
{
- TextReader input = new StreamReader(stream);
+ var input = new StreamReader(stream);
- JsonReader reader = new JsonReader(new DataReaderSettings());
+ var reader = new JsonReader(new DataReaderSettings());
dynamic actual = reader.Read(input);
Assert.Equal(2, actual.Length);
}
}
+ class ClassA
+ {
+ public int a;
+ }
+
+ [Fact]
+ [Trait(TraitName, TraitValue)]
+ public void Read_NullValueTypes()
+ {
+ var input = "{a:null}";
+
+ var settings = new DataReaderSettings();
+ settings.AllowNullValueTypes = true;
+
+ var reader = new JsonReader(settings);
+
+ var actual = reader.Read<ClassA>(input);
+
+ Assert.Equal(default(int), actual.a);
+ }
+
#endregion Object Tests
#region Enum Tests
@@ -2,11 +2,11 @@
This is auto-generated code. All changes will be overwritten.
\*------------------------------------------------------------------*/
-#region 2.0.1209.2801
+#region 2.0.1209.2802
using System.Reflection;
-[assembly: AssemblyVersion("2.0.1209.2801")]
-[assembly: AssemblyFileVersion("2.0.1209.2801")]
+[assembly: AssemblyVersion("2.0.1209.2802")]
+[assembly: AssemblyFileVersion("2.0.1209.2802")]
-#endregion 2.0.1209.2801
+#endregion 2.0.1209.2802
@@ -264,7 +264,17 @@ internal void SetMemberValue(object target, Type targetType, MemberMap memberMap
}
else if (memberMap != null && memberMap.Setter != null)
{
- memberMap.Setter(target, this.CoerceType(memberMap.Type, memberValue));
+ if (memberValue == null)
+ {
+ memberMap.Setter(target,
+ memberMap.Type.IsValueType ?
+ Activator.CreateInstance(memberMap.Type, true) :
+ null);
+ }
+ else
+ {
+ memberMap.Setter(target, this.CoerceType(memberMap.Type, memberValue));
+ }
}
// ignore non-applicable members

0 comments on commit 3fa7bc3

Please sign in to comment.