Skip to content

Commit

Permalink
2.1.34
Browse files Browse the repository at this point in the history
- ability to create internal/private objects (removed the public access restriction on classes)
  • Loading branch information
mgholam committed Jun 28, 2018
1 parent a53a905 commit ca87c04
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
29 changes: 24 additions & 5 deletions UnitTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2813,18 +2813,18 @@ public static void ConvertTest()
var data2 = JSON.ToObject<TestData>(jsonData);

// OK, since data member name is "foo" which is all in lower case
Assert.AreEqual(data.Foo ,data2.Foo);
Assert.AreEqual(data.Foo, data2.Foo);

// Fails, since data member name is "Bar", but the library looks for "bar" when setting the value
Assert.AreEqual(data.Bar , data2.Bar);
Assert.AreEqual(data.Bar, data2.Bar);
}


public class test { public string name = "me"; }
[Test]
public static void ArrayOfObjectExtOff()
{
var s = JSON.ToJSON(new test[] { new test(), new test() }, new JSONParameters { UseExtensions = false});
var s = JSON.ToJSON(new test[] { new test(), new test() }, new JSONParameters { UseExtensions = false });
var o = JSON.ToObject<test[]>(s);
Console.WriteLine(o.GetType().ToString());
Assert.AreEqual(typeof(test[]), o.GetType());
Expand Down Expand Up @@ -2897,7 +2897,7 @@ public static void dicofdic()
var s = "{ 'Section1' : { 'Key1' : 'Value1', 'Key2' : 'Value2', 'Key3' : 'Value3', 'Key4' : 'Value4', 'Key5' : 'Value5' } }".Replace("\'", "\"");
var o = JSON.ToObject<Dictionary<string, Dictionary<string, string>>>(s);
var v = o["Section1"];

Assert.AreEqual(5, v.Count);
Assert.AreEqual("Value2", v["Key2"]);
}
Expand Down Expand Up @@ -2940,7 +2940,7 @@ public class nsb
[Test]
public static void NonStrictBoolean()
{
var s = "{'one':1,'two':'1','three':'true','four':'on','five':'yes'}".Replace("\'","\"");
var s = "{'one':1,'two':'1','three':'true','four':'on','five':'yes'}".Replace("\'", "\"");

var o = JSON.ToObject<nsb>(s);
Assert.AreEqual(true, o.one);
Expand All @@ -2949,5 +2949,24 @@ public static void NonStrictBoolean()
Assert.AreEqual(true, o.four);
Assert.AreEqual(true, o.five);
}

private class npc
{
public int a = 1;
public int b = 2;
}
[Test]
public static void NonPublicClass()
{
var p = new npc();
p.a = 10;
p.b = 20;
var s = JSON.ToJSON(p);
var o = (npc)JSON.ToObject(s);
Assert.AreEqual(10, o.a);
Assert.AreEqual(20, o.b);
}


}// UnitTests.Tests
//}
2 changes: 1 addition & 1 deletion fastJSON.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>fastJSON</id>
<version>2.1.33.0</version>
<version>2.1.34.0</version>
<title>fastJSON</title>
<authors>mgholam</authors>
<owners />
Expand Down
2 changes: 1 addition & 1 deletion fastJSON/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@


[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.33.0")]
[assembly: AssemblyFileVersion("2.1.34.0")]
4 changes: 2 additions & 2 deletions fastJSON/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ internal object FastCreateInstance(Type objtype)
{
if (objtype.IsClass)
{
DynamicMethod dynMethod = new DynamicMethod("_", objtype, null);
DynamicMethod dynMethod = new DynamicMethod("_", objtype, null, true);
ILGenerator ilGen = dynMethod.GetILGenerator();
ilGen.Emit(OpCodes.Newobj, objtype.GetConstructor(Type.EmptyTypes));
ilGen.Emit(OpCodes.Ret);
Expand All @@ -368,7 +368,7 @@ internal object FastCreateInstance(Type objtype)
}
else // structs
{
DynamicMethod dynMethod = new DynamicMethod("_", typeof(object), null);
DynamicMethod dynMethod = new DynamicMethod("_", typeof(object), null, true);
ILGenerator ilGen = dynMethod.GetILGenerator();
var lv = ilGen.DeclareLocal(objtype);
ilGen.Emit(OpCodes.Ldloca_S, lv);
Expand Down
2 changes: 1 addition & 1 deletion fastJSONcore/fastJSON.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;net4.0</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>2.1.0.0</Version>
<FileVersion>2.1.33.0</FileVersion>
<FileVersion>2.1.34.0</FileVersion>
<Description>smallest fastest polymorphic json serializer</Description>
<Copyright>2010-2018</Copyright>
<Authors>M. Gholam</Authors>
Expand Down
4 changes: 4 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
2.1.34
- ability to create internal/private objects (removed the public access restriction on classes)

2.1.33
- case insensitive enum (thanks to AgentFire)
- auto covert to boolean (number >0 , string : 1, true, yes, on)
- fixed .net 3.5 project output framework version

2.1.32
- Non public setter / readonly property support (thanks to rbeurskens)
Expand Down

0 comments on commit ca87c04

Please sign in to comment.