Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
- Update license
- Update fastJSON to 2.4.0.5
- Add support for many tfms (including limited support for .NET Core 1.0 and Standard 1.5)
- Binary compat fix: specify enum values for 'myPropInfoType' explicitly (wouldn't have affected any existing distribution of this library)
  • Loading branch information
hamarb123 committed Jan 23, 2023
1 parent 542ad25 commit 7274c75
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 157 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2010-2021 Mehdi Gholam
Copyright (c) 2020-2021 Hamish Arblaster
Copyright (c) 2020-2023 Hamish Arblaster

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ The [fastJSON how to](https://github.com/mgholam/fastJSON/blob/master/Howto.md)

Supported platforms:
- .NET Framework 4.0
- .NET Framework 4.5
- .NET Standard 1.5 (limited support)
- .NET Standard 2.0
- .NET Standard 2.1
- .NET Core 1.0 (limited support)
- .NET Core 2.0
- .NET Core 2.1
- .NET Core 3.0
- .NET Core 3.1
- .NET 5.0
- .NET 6.0
- .NET 7.0
- And any platforms compatible with the above tfms

Limited support: you should test that the code works on each specific runtime you plan to build for as required APIs may not be available at runtime.

When building the project for yourself, open the fastJSONCore.sln solution and build the fastJSON5Builder project to create the executables. Use the fastJSON project at fastJSONcore/fastJSON.csproj (fastJSON in the sln file) to modify the library files. The UnitTests/UnitTestsCore.csproj project (UnitTestsCore in the sln file) is used to do the testing, so use it for anything relating to tests. The UnitTests/UnitTests.csproj project (UnitTests in the sln file) is the test project for .NET Framework.
You may encounter issues building if you have the fastJSON.csproj file open in Visual Studio, try closing it if you do.

Expand Down
98 changes: 62 additions & 36 deletions UnitTests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
using System.Data;
#endif
#if !SILVERLIGHT
using NUnit.Framework;
using System.Data;
#endif
using System.Collections;
using System.Threading;
Expand Down Expand Up @@ -48,10 +50,10 @@ public static void IsInstanceOf<T>(object o)
#endif
public class tests
{
#region [ helpers ]
#region [ helpers ]
static int thousandtimes = 1000;
static int fivetimes = 5;
#if !SILVERLIGHT
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
static DataSet ds = new DataSet();
#endif
//static bool exotic = false;
Expand Down Expand Up @@ -91,11 +93,13 @@ ahjksjkAHJKS سلام فارسی
public bool isNew { get; set; }
public string laststring { get; set; }
public Gender gender { get; set; }
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
public DataSet dataset { get; set; }
#endif
#if !SILVERLIGHT
public DataSet dataset { get; set; }
public Hashtable hash { get; set; }
#endif
public Dictionary<string, baseclass> stringDictionary { get; set; }
public Dictionary<string, baseclass> stringDictionary { get; set; }
public Dictionary<baseclass, baseclass> objectDictionary { get; set; }
public Dictionary<int, baseclass> intDictionary { get; set; }
public Guid? nullableGuid { get; set; }
Expand All @@ -122,10 +126,12 @@ public static colclass CreateObject(bool exotic, bool dataset)
c.hash = new Hashtable();
c.hash.Add(new class1("0", "hello", Guid.NewGuid()), new class2("1", "code", "desc"));
c.hash.Add(new class2("0", "hello", "pppp"), new class1("1", "code", Guid.NewGuid()));
if (dataset)
#endif
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
if (dataset)
c.dataset = CreateDataset();
#endif
c.bytes = new byte[1024];
c.bytes = new byte[1024];
c.stringDictionary = new Dictionary<string, baseclass>();
c.objectDictionary = new Dictionary<baseclass, baseclass>();
c.intDictionary = new Dictionary<int, baseclass>();
Expand Down Expand Up @@ -211,8 +217,8 @@ public class Retclass
public object obj;
public string ppp { get { return "sdfas df "; } }
public DateTime date { get; set; }
#if !SILVERLIGHT
public DataTable ds { get; set; }
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
public DataTable ds { get; set; }
#endif
}

Expand All @@ -224,8 +230,8 @@ public struct Retstruct
public int Field2;
public string ppp { get { return "sdfas df "; } }
public DateTime date { get; set; }
#if !SILVERLIGHT
public DataTable ds { get; set; }
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
public DataTable ds { get; set; }
#endif
}

Expand All @@ -249,8 +255,8 @@ private static long CreateLong(string s)
return neg ? -num : num;
}

#if !SILVERLIGHT
private static DataSet CreateDataset()
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
private static DataSet CreateDataset()
{
DataSet ds = new DataSet();
for (int j = 1; j < 3; j++)
Expand Down Expand Up @@ -289,9 +295,9 @@ public class RetNestedclass
public Retclass Nested { get; set; }
}

#endregion
#endregion

#if NET4
#if !CORE_TEST
[TestFixtureSetUp]
#else
[OneTimeSetUp]
Expand All @@ -318,8 +324,8 @@ public static void ClassTest()
r.Field1 = "dsasdF";
r.Field2 = 2312;
r.date = DateTime.Now;
#if !SILVERLIGHT
r.ds = CreateDataset().Tables[0];
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
r.ds = CreateDataset().Tables[0];
#endif

var s = JSON.ToJSON(r);
Expand All @@ -338,8 +344,8 @@ public static void StructTest()
r.Field1 = "dsasdF";
r.Field2 = 2312;
r.date = DateTime.Now;
#if !SILVERLIGHT
r.ds = CreateDataset().Tables[0];
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
r.ds = CreateDataset().Tables[0];
#endif

var s = JSON.ToNiceJSON(r);
Expand All @@ -357,8 +363,8 @@ public static void ParseTest()
r.Field1 = "dsasdF";
r.Field2 = 2312;
r.date = DateTime.Now;
#if !SILVERLIGHT
r.ds = CreateDataset().Tables[0];
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
r.ds = CreateDataset().Tables[0];
#endif

var s = JSON.ToJSON(r);
Expand Down Expand Up @@ -878,7 +884,8 @@ public static void SingleCharNumber()
Assert.That(zero, Is.EqualTo(o));
}


#endif
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)

[Test]
public static void Datasets()
Expand Down Expand Up @@ -908,8 +915,10 @@ public static void Datasets()
Assert.AreEqual(100, oo.Rows.Count);
}

#endif
#if !SILVERLIGHT

[Test]
[Test]
public static void DynamicTest()
{
string s = "{\"Name\":\"aaaaaa\",\"Age\":10,\"dob\":\"2000-01-01 00:00:00Z\",\"inner\":{\"prop\":30},\"arr\":[1,{\"a\":2},3,4,5,6]}";
Expand Down Expand Up @@ -950,7 +959,7 @@ public static void GetDynamicMemberNamesTests()
}
#endif

[Test]
[Test]
public static void CommaTests()
{
var s = JSON.ToJSON(new commaclass(), new JSONParameters() { UseExtensions = true });
Expand Down Expand Up @@ -1882,7 +1891,7 @@ public static void comments()
Assert.AreEqual(2, (o as IDictionary).Count);
}

#if NET4
#if !CORE_TEST || NETFRAMEWORK || !NETCOREAPP3_0_OR_GREATER
public class ctype
{
public System.Net.IPAddress ip;
Expand Down Expand Up @@ -2067,7 +2076,7 @@ public static void bytearrindic()
var d = JSON.ToObject<Dictionary<string, byte[]>>(s);
}

#region twitter
#region twitter
public class Twitter
{
public Query query { get; set; }
Expand Down Expand Up @@ -2119,11 +2128,11 @@ public class BoundingBox
public string type { get; set; }
}
}
#endregion
#endregion
[Test]
public static void twitter()
{
#region tw data
#region tw data
string ss = @"{
""query"": {
""params"": {
Expand Down Expand Up @@ -2481,7 +2490,7 @@ public static void twitter()
]
}
}";
#endregion
#endregion
var o = JSON.ToObject<Twitter>(ss);
}

Expand Down Expand Up @@ -3516,7 +3525,8 @@ public static void UTCDateFalse()
var dt = new DateTime(2021, 1, 10, 12, 0, 0, DateTimeKind.Utc);
var js = JSON.ToJSON(dt);
Console.WriteLine(js);
Assert.AreEqual(15, JSON.ToObject<DateTime>(js, new JSONParameters() { UseUTCDateTime = false }).Hour);
var dt2 = DateTime.SpecifyKind(dt.ToLocalTime(), DateTimeKind.Utc);
Assert.AreEqual(dt2.Hour, JSON.ToObject<DateTime>(js, new JSONParameters() { UseUTCDateTime = false }).Hour);
}
//[Test]
//public static void ma()
Expand Down Expand Up @@ -3915,19 +3925,35 @@ public static void json5_additional_tests_3()
Console.WriteLine("Test for -0x0 --> -0");

Assert.AreEqual(
#if NET4
#if NETFRAMEWORK || NET4 || NETCOREAPP && !NETCOREAPP3_0_OR_GREATER
"9.0144042682896313E+28"
#else
"9.014404268289631E+28"
#endif
, JSON.ToJSON(JSON.Parse("+0x0123456789abcdefABCDEF0000")));
Console.WriteLine("Test for long hex number");

AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("..2"));
Console.WriteLine(".. is illegal");

AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("{a:..2}"));
Console.WriteLine(".. is illegal inside of an object");
try
{
AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("..2"));
Console.WriteLine(".. is illegal");
}
catch
{
AssertException(typeof(FormatException), "The input string '..2' was not in a correct format.", () => JSON.Parse("..2"));
Console.WriteLine(".. is illegal");
}

try
{
AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("{a:..2}"));
Console.WriteLine(".. is illegal inside of an object");
}
catch
{
AssertException(typeof(FormatException), "The input string '..2' was not in a correct format.", () => JSON.Parse("{a:..2}"));
Console.WriteLine(".. is illegal inside of an object");
}

Assert.AreEqual(1e41, JSON.Parse("100000000000000000000000000000000000000000"));
Console.WriteLine("Parses 100000000000000000000000000000000000000000");
Expand Down
8 changes: 7 additions & 1 deletion UnitTests/UnitTestsCore.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net47;netcoreapp2.1;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);CORE_TEST</DefineConstants>
<NoWarn>$(NoWarn);CS8981</NoWarn>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit.Extension.NUnitV2Driver" Version="3.8.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="IndexRange" Version="1.0.2" />
<Reference Include="Microsoft.CSharp.dll" Condition=" '$(TargetFramework)' == 'net47' " />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 7274c75

Please sign in to comment.