Skip to content

Commit 3e2e11b

Browse files
authored
Use Newtonsoft.Json.Bson except in NetCore projects (#370)
- avoid obsolete `BsonReader` and `BsonWriter` classes - use `NETFX_CORE` for remaining legacy case (for now) - remove `NEWTONSOFTJSON10` define; need only `NETFX_CORE` now
1 parent d2c6660 commit 3e2e11b

File tree

8 files changed

+22
-12
lines changed

8 files changed

+22
-12
lines changed

src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<OutputPath>$(OutputPath)NetStandard\</OutputPath>
88
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
99
<RunCodeAnalysis>false</RunCodeAnalysis>
10-
<DefineConstants>$(DefineConstants);ASPNETMVC;NEWTONSOFTJSON10</DefineConstants>
10+
<DefineConstants>$(DefineConstants);ASPNETMVC</DefineConstants>
1111
<NoWarn>1591</NoWarn>
1212
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1313
<Configurations>$(Configurations);CodeAnalysis</Configurations>

src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
using System.Threading.Tasks;
1212
using System.Web.Http;
1313
using Newtonsoft.Json;
14-
#if NEWTONSOFTJSON10
14+
#if NETFX_CORE
15+
using Newtonsoft.Json.Bson;
16+
#else
1517
using BsonReader = Newtonsoft.Json.Bson.BsonDataReader;
1618
using BsonWriter = Newtonsoft.Json.Bson.BsonDataWriter;
17-
#else
18-
using Newtonsoft.Json.Bson;
1919
#endif
2020

2121
namespace System.Net.Http.Formatting
@@ -200,11 +200,11 @@ public override JsonReader CreateJsonReader(Type type, Stream readStream, Encodi
200200
throw Error.ArgumentNull("effectiveEncoding");
201201
}
202202

203-
#if !NEWTONSOFTJSON10
203+
#if NETFX_CORE
204204
#pragma warning disable CS0618 // Type or member is obsolete
205205
#endif
206206
BsonReader reader = new BsonReader(new BinaryReader(readStream, effectiveEncoding));
207-
#if !NEWTONSOFTJSON10
207+
#if NETFX_CORE
208208
#pragma warning restore CS0618 // Type or member is obsolete
209209
#endif
210210

@@ -303,11 +303,11 @@ public override JsonWriter CreateJsonWriter(Type type, Stream writeStream, Encod
303303
throw Error.ArgumentNull("effectiveEncoding");
304304
}
305305

306-
#if !NEWTONSOFTJSON10
306+
#if NETFX_CORE
307307
#pragma warning disable CS0618 // Type or member is obsolete
308308
#endif
309309
return new BsonWriter(new BinaryWriter(writeStream, effectiveEncoding));
310-
#if !NEWTONSOFTJSON10
310+
#if NETFX_CORE
311311
#pragma warning restore CS0618 // Type or member is obsolete
312312
#endif
313313
}

src/System.Net.Http.Formatting/System.Net.Http.Formatting.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<SpecificVersion>False</SpecificVersion>
2121
<Private>False</Private>
2222
</Reference>
23+
<Reference Include="Newtonsoft.Json.Bson, Version=1.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
24+
<HintPath>..\..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll</HintPath>
25+
<SpecificVersion>False</SpecificVersion>
26+
<Private>False</Private>
27+
</Reference>
2328
<Reference Include="System" />
2429
<Reference Include="System.Configuration" />
2530
<Reference Include="System.Core" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
4+
<package id="Newtonsoft.Json.Bson" version="1.0.2" targetFramework="net45" />
45
</packages>

test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<RootNamespace>System.Net.Http</RootNamespace>
66
<AssemblyName>System.Net.Http.Formatting.NetStandard.Test</AssemblyName>
77
<OutputPath>..\..\bin\$(Configuration)\Test\</OutputPath>
8-
<DefineConstants>$(DefineConstants);NEWTONSOFTJSON10</DefineConstants>
98
<Configurations>$(Configurations);CodeAnalysis</Configurations>
109
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1110
</PropertyGroup>

test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ public async Task FormatterThrowsOnWriteWithInvalidContent()
262262
BsonMediaTypeFormatter formatter = new BsonMediaTypeFormatter();
263263
HttpContent content = new StringContent(String.Empty);
264264
MemoryStream stream = new MemoryStream();
265-
#if NEWTONSOFTJSON10 // Json.NET 10's Bson package calculates the path in some exceptions differently.
266-
string expectedPath = "Value";
267-
#else
265+
#if NETFX_CORE // Separate Bson package (not yet used in NETCore project) calculates the path in exceptions differently
268266
string expectedPath = string.Empty;
267+
#else
268+
string expectedPath = "Value";
269269
#endif
270270
string expectedMessage = string.Format(
271271
"Value is too large to fit in a signed 32 bit integer. BSON does not support unsigned values. Path '{0}'.",

test/System.Net.Http.Formatting.Test/System.Net.Http.Formatting.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
2727
<Private>True</Private>
2828
</Reference>
29+
<Reference Include="Newtonsoft.Json.Bson, Version=1.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
30+
<HintPath>..\..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll</HintPath>
31+
<Private>True</Private>
32+
</Reference>
2933
<Reference Include="System" />
3034
<Reference Include="System.Configuration" />
3135
<Reference Include="System.Data" />

test/System.Net.Http.Formatting.Test/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<package id="Castle.Core" version="4.2.1" targetFramework="net452" />
44
<package id="Moq" version="4.7.142" targetFramework="net452" />
55
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net452" />
6+
<package id="Newtonsoft.Json.Bson" version="1.0.2" targetFramework="net452" />
67
<package id="xunit" version="2.3.0" targetFramework="net452" />
78
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
89
<package id="xunit.analyzers" version="0.7.0" targetFramework="net452" />

0 commit comments

Comments
 (0)