Skip to content

Commit 7274c75

Browse files
committed
1.0.4
- 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)
1 parent 542ad25 commit 7274c75

14 files changed

+514
-157
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) 2010-2021 Mehdi Gholam
4-
Copyright (c) 2020-2021 Hamish Arblaster
4+
Copyright (c) 2020-2023 Hamish Arblaster
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ The [fastJSON how to](https://github.com/mgholam/fastJSON/blob/master/Howto.md)
1010

1111
Supported platforms:
1212
- .NET Framework 4.0
13+
- .NET Framework 4.5
14+
- .NET Standard 1.5 (limited support)
1315
- .NET Standard 2.0
1416
- .NET Standard 2.1
17+
- .NET Core 1.0 (limited support)
18+
- .NET Core 2.0
19+
- .NET Core 2.1
20+
- .NET Core 3.0
21+
- .NET Core 3.1
1522
- .NET 5.0
23+
- .NET 6.0
24+
- .NET 7.0
1625
- And any platforms compatible with the above tfms
1726

27+
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.
28+
1829
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.
1930
You may encounter issues building if you have the fastJSON.csproj file open in Visual Studio, try closing it if you do.
2031

UnitTests/Tests.cs

+62-36
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
4+
using System.Data;
5+
#endif
36
#if !SILVERLIGHT
47
using NUnit.Framework;
5-
using System.Data;
68
#endif
79
using System.Collections;
810
using System.Threading;
@@ -48,10 +50,10 @@ public static void IsInstanceOf<T>(object o)
4850
#endif
4951
public class tests
5052
{
51-
#region [ helpers ]
53+
#region [ helpers ]
5254
static int thousandtimes = 1000;
5355
static int fivetimes = 5;
54-
#if !SILVERLIGHT
56+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
5557
static DataSet ds = new DataSet();
5658
#endif
5759
//static bool exotic = false;
@@ -91,11 +93,13 @@ ahjksjkAHJKS سلام فارسی
9193
public bool isNew { get; set; }
9294
public string laststring { get; set; }
9395
public Gender gender { get; set; }
96+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
97+
public DataSet dataset { get; set; }
98+
#endif
9499
#if !SILVERLIGHT
95-
public DataSet dataset { get; set; }
96100
public Hashtable hash { get; set; }
97101
#endif
98-
public Dictionary<string, baseclass> stringDictionary { get; set; }
102+
public Dictionary<string, baseclass> stringDictionary { get; set; }
99103
public Dictionary<baseclass, baseclass> objectDictionary { get; set; }
100104
public Dictionary<int, baseclass> intDictionary { get; set; }
101105
public Guid? nullableGuid { get; set; }
@@ -122,10 +126,12 @@ public static colclass CreateObject(bool exotic, bool dataset)
122126
c.hash = new Hashtable();
123127
c.hash.Add(new class1("0", "hello", Guid.NewGuid()), new class2("1", "code", "desc"));
124128
c.hash.Add(new class2("0", "hello", "pppp"), new class1("1", "code", Guid.NewGuid()));
125-
if (dataset)
129+
#endif
130+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
131+
if (dataset)
126132
c.dataset = CreateDataset();
127133
#endif
128-
c.bytes = new byte[1024];
134+
c.bytes = new byte[1024];
129135
c.stringDictionary = new Dictionary<string, baseclass>();
130136
c.objectDictionary = new Dictionary<baseclass, baseclass>();
131137
c.intDictionary = new Dictionary<int, baseclass>();
@@ -211,8 +217,8 @@ public class Retclass
211217
public object obj;
212218
public string ppp { get { return "sdfas df "; } }
213219
public DateTime date { get; set; }
214-
#if !SILVERLIGHT
215-
public DataTable ds { get; set; }
220+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
221+
public DataTable ds { get; set; }
216222
#endif
217223
}
218224

@@ -224,8 +230,8 @@ public struct Retstruct
224230
public int Field2;
225231
public string ppp { get { return "sdfas df "; } }
226232
public DateTime date { get; set; }
227-
#if !SILVERLIGHT
228-
public DataTable ds { get; set; }
233+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
234+
public DataTable ds { get; set; }
229235
#endif
230236
}
231237

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

252-
#if !SILVERLIGHT
253-
private static DataSet CreateDataset()
258+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
259+
private static DataSet CreateDataset()
254260
{
255261
DataSet ds = new DataSet();
256262
for (int j = 1; j < 3; j++)
@@ -289,9 +295,9 @@ public class RetNestedclass
289295
public Retclass Nested { get; set; }
290296
}
291297

292-
#endregion
298+
#endregion
293299

294-
#if NET4
300+
#if !CORE_TEST
295301
[TestFixtureSetUp]
296302
#else
297303
[OneTimeSetUp]
@@ -318,8 +324,8 @@ public static void ClassTest()
318324
r.Field1 = "dsasdF";
319325
r.Field2 = 2312;
320326
r.date = DateTime.Now;
321-
#if !SILVERLIGHT
322-
r.ds = CreateDataset().Tables[0];
327+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
328+
r.ds = CreateDataset().Tables[0];
323329
#endif
324330

325331
var s = JSON.ToJSON(r);
@@ -338,8 +344,8 @@ public static void StructTest()
338344
r.Field1 = "dsasdF";
339345
r.Field2 = 2312;
340346
r.date = DateTime.Now;
341-
#if !SILVERLIGHT
342-
r.ds = CreateDataset().Tables[0];
347+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
348+
r.ds = CreateDataset().Tables[0];
343349
#endif
344350

345351
var s = JSON.ToNiceJSON(r);
@@ -357,8 +363,8 @@ public static void ParseTest()
357363
r.Field1 = "dsasdF";
358364
r.Field2 = 2312;
359365
r.date = DateTime.Now;
360-
#if !SILVERLIGHT
361-
r.ds = CreateDataset().Tables[0];
366+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
367+
r.ds = CreateDataset().Tables[0];
362368
#endif
363369

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

881-
887+
#endif
888+
#if !SILVERLIGHT && (NETFRAMEWORK || NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET4)
882889

883890
[Test]
884891
public static void Datasets()
@@ -908,8 +915,10 @@ public static void Datasets()
908915
Assert.AreEqual(100, oo.Rows.Count);
909916
}
910917

918+
#endif
919+
#if !SILVERLIGHT
911920

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

953-
[Test]
962+
[Test]
954963
public static void CommaTests()
955964
{
956965
var s = JSON.ToJSON(new commaclass(), new JSONParameters() { UseExtensions = true });
@@ -1882,7 +1891,7 @@ public static void comments()
18821891
Assert.AreEqual(2, (o as IDictionary).Count);
18831892
}
18841893

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

2070-
#region twitter
2079+
#region twitter
20712080
public class Twitter
20722081
{
20732082
public Query query { get; set; }
@@ -2119,11 +2128,11 @@ public class BoundingBox
21192128
public string type { get; set; }
21202129
}
21212130
}
2122-
#endregion
2131+
#endregion
21232132
[Test]
21242133
public static void twitter()
21252134
{
2126-
#region tw data
2135+
#region tw data
21272136
string ss = @"{
21282137
""query"": {
21292138
""params"": {
@@ -2481,7 +2490,7 @@ public static void twitter()
24812490
]
24822491
}
24832492
}";
2484-
#endregion
2493+
#endregion
24852494
var o = JSON.ToObject<Twitter>(ss);
24862495
}
24872496

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

39173927
Assert.AreEqual(
3918-
#if NET4
3928+
#if NETFRAMEWORK || NET4 || NETCOREAPP && !NETCOREAPP3_0_OR_GREATER
39193929
"9.0144042682896313E+28"
39203930
#else
39213931
"9.014404268289631E+28"
39223932
#endif
39233933
, JSON.ToJSON(JSON.Parse("+0x0123456789abcdefABCDEF0000")));
39243934
Console.WriteLine("Test for long hex number");
39253935

3926-
AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("..2"));
3927-
Console.WriteLine(".. is illegal");
3928-
3929-
AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("{a:..2}"));
3930-
Console.WriteLine(".. is illegal inside of an object");
3936+
try
3937+
{
3938+
AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("..2"));
3939+
Console.WriteLine(".. is illegal");
3940+
}
3941+
catch
3942+
{
3943+
AssertException(typeof(FormatException), "The input string '..2' was not in a correct format.", () => JSON.Parse("..2"));
3944+
Console.WriteLine(".. is illegal");
3945+
}
3946+
3947+
try
3948+
{
3949+
AssertException(typeof(FormatException), "Input string was not in a correct format.", () => JSON.Parse("{a:..2}"));
3950+
Console.WriteLine(".. is illegal inside of an object");
3951+
}
3952+
catch
3953+
{
3954+
AssertException(typeof(FormatException), "The input string '..2' was not in a correct format.", () => JSON.Parse("{a:..2}"));
3955+
Console.WriteLine(".. is illegal inside of an object");
3956+
}
39313957

39323958
Assert.AreEqual(1e41, JSON.Parse("100000000000000000000000000000000000000000"));
39333959
Console.WriteLine("Parses 100000000000000000000000000000000000000000");

UnitTests/UnitTestsCore.csproj

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFrameworks>net47;netcoreapp2.1;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
5+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
56
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
67
<IsPackable>false</IsPackable>
78
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
<DefineConstants>$(DefineConstants);CORE_TEST</DefineConstants>
10+
<NoWarn>$(NoWarn);CS8981</NoWarn>
11+
<LangVersion>9</LangVersion>
812
</PropertyGroup>
913

1014
<ItemGroup>
1115
<PackageReference Include="NUnit" Version="3.12.0" />
1216
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
1317
<PackageReference Include="NUnit.Extension.NUnitV2Driver" Version="3.8.0" />
1418
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
19+
<PackageReference Include="IndexRange" Version="1.0.2" />
20+
<Reference Include="Microsoft.CSharp.dll" Condition=" '$(TargetFramework)' == 'net47' " />
1521
</ItemGroup>
1622

1723
<ItemGroup>

0 commit comments

Comments
 (0)