Skip to content

Commit 36af357

Browse files
committed
- Fixed #137
Signed-off-by: rpgmaker <[email protected]>
1 parent 67bf260 commit 36af357

File tree

13 files changed

+30
-9
lines changed

13 files changed

+30
-9
lines changed

NetJSON.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
// You can specify all the values or you can default the Build and Revision Numbers
2525
// by using the '*' as shown below:
2626
// [assembly: AssemblyVersion("1.0.*")]
27-
[assembly: AssemblyVersion("1.2.1.3")]
28-
[assembly: AssemblyFileVersion("1.2.1.3")]
27+
[assembly: AssemblyVersion("1.2.1.4")]
28+
[assembly: AssemblyFileVersion("1.2.1.4")]

NetJSON.Core/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
}
2323
},
2424
"title": "NetJSON",
25-
"version": "1.2.1.3"
25+
"version": "1.2.1.4"
2626
}

NetJSON.Tests/SerializeTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ public void NullableWithDefaultValueSetSerializes()
233233
Assert.AreEqual("{\"x\":0}", json);
234234
}
235235

236+
[TestMethod]
237+
public void NonDefaultNullableValueSerializes()
238+
{
239+
var obj = new NullableTest { x = 5 };
240+
var settings = new NetJSONSettings { SkipDefaultValue = true };
241+
var json = NetJSON.Serialize(obj, settings);
242+
Assert.AreEqual("{\"x\":5}", json);
243+
}
244+
236245
public class TestJSON {
237246
public List<Rec> d { get; set; }
238247
public List<int?> v { get; set; }

NetJSON/NetJSON.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,9 +2831,13 @@ internal static void WritePropertiesFor(TypeBuilder typeBuilder, Type type, ILGe
28312831
var skipDefaultValueTrueLabel = il.DefineLabel();
28322832
var skipDefaultValueFalseLabel = il.DefineLabel();
28332833
var skipDefaultValueTrueAndHasValueLabel = il.DefineLabel();
2834+
var successLocal = il.DeclareLocal(_boolType);
28342835

28352836
var hasValueMethod = isNullable ? originPropType.GetMethod("get_HasValue") : null;
28362837

2838+
il.Emit(OpCodes.Ldc_I4, 0);
2839+
il.Emit(OpCodes.Stloc, successLocal);
2840+
28372841
il.Emit(OpCodes.Ldloc, skipDefaultValue);
28382842
il.Emit(OpCodes.Brfalse, skipDefaultValueTrueLabel);
28392843

@@ -2878,16 +2882,24 @@ internal static void WritePropertiesFor(TypeBuilder typeBuilder, Type type, ILGe
28782882

28792883
WritePropertyForType(typeBuilder, il, hasValue, counter, nameLocal, propType, propValue);
28802884

2885+
il.Emit(OpCodes.Ldc_I4, 1);
2886+
il.Emit(OpCodes.Stloc, successLocal);
2887+
28812888
il.MarkLabel(propNullLabel);
28822889

28832890
il.MarkLabel(skipDefaultValueTrueLabel);
28842891

28852892

28862893
il.Emit(OpCodes.Ldloc, skipDefaultValue);
28872894
il.Emit(OpCodes.Brtrue, skipDefaultValueFalseLabel);
2895+
il.Emit(OpCodes.Ldloc, successLocal);
2896+
il.Emit(OpCodes.Brtrue, skipDefaultValueFalseLabel);
28882897

28892898
WritePropertyForType(typeBuilder, il, hasValue, counter, nameLocal, propType, propValue);
28902899

2900+
il.Emit(OpCodes.Ldc_I4, 1);
2901+
il.Emit(OpCodes.Stloc, successLocal);
2902+
28912903
il.MarkLabel(skipDefaultValueFalseLabel);
28922904

28932905
if (isNullable)
@@ -2897,6 +2909,8 @@ internal static void WritePropertiesFor(TypeBuilder typeBuilder, Type type, ILGe
28972909
il.Emit(OpCodes.Ldloca, nullablePropValue);
28982910
il.Emit(OpCodes.Call, hasValueMethod);
28992911
il.Emit(OpCodes.Brfalse, skipDefaultValueTrueAndHasValueLabel);
2912+
il.Emit(OpCodes.Ldloc, successLocal);
2913+
il.Emit(OpCodes.Brtrue, skipDefaultValueTrueAndHasValueLabel);
29002914

29012915
WritePropertyForType(typeBuilder, il, hasValue, counter, nameLocal, propType, propValue);
29022916

NetJSON/NetJSON.nuspec

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
<id>NetJSON</id>
55
<title>NetJSON</title>
66
<tags>json json-serializer javascript JSON serializer binary</tags>
7-
<version>1.2.1.3</version>
7+
<version>1.2.1.4</version>
88
<authors>TJ Bakre</authors>
99
<description>Faster than Any Binary?</description>
1010
<releaseNotes>
11-
Added support for netstandard1.6
12-
Fixed issue with skipping default value when nullable is used
13-
Fixed issue with failure for date serialization due to missing "Z"
11+
Fixed nullable issue with skip default option
1412
</releaseNotes>
1513
<language>en-US</language>
1614
<licenseUrl>https://github.com/rpgmaker/NetJSON/blob/master/LICENSE.text</licenseUrl>

NetJSON/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.2.1.3")]
37-
[assembly: AssemblyFileVersion("1.2.1.3")]
36+
[assembly: AssemblyVersion("1.2.1.4")]
37+
[assembly: AssemblyFileVersion("1.2.1.4")]
3838
#if !NET_35
3939
[assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust = true)]
4040
#endif

NetJSON/lib/dnx/NetJSON.Core.dll

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

NetJSON/lib/net35/NetJSON.dll

0 Bytes
Binary file not shown.

NetJSON/lib/net40/NetJSON.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)