Skip to content

Commit

Permalink
FIX: Using Newtonsoft.Json as the default serializer
Browse files Browse the repository at this point in the history
By default the AspNet.Core Serializer on 3.0+ is the System.Text.Json, the current implementation of the library doesn't support Fields only Properties even public fields.

There is a change that will be part of .net 5.0 that will provide a option to change this behaviour
dotnet/runtime#36986
  • Loading branch information
ViniciusSouza committed Sep 3, 2020
1 parent 87e2135 commit 106cd82
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Arriba/Arriba.Composition/Arriba.Composition.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Adapters\Arriba.Adapter.Cache\Arriba.Adapter.Cache.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion src/Arriba/Arriba.Server/Arriba.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.7" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
Expand Down
25 changes: 16 additions & 9 deletions src/Arriba/Arriba.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Arriba.Client.Serialization.Json;
using Arriba.Communication;
using Arriba.Composition;
using Arriba.Configuration;
Expand Down Expand Up @@ -49,8 +50,14 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton(serverConfig);
services.AddSingleton((_) => serverConfig.OAuthConfig);
services.AddOAuth(serverConfig);
services.AddControllers();

services.AddControllers().AddNewtonsoftJson(options =>
{
foreach (var converter in ConverterFactory.GetArribaConverters())
{
options.SerializerSettings.Converters.Add(converter);
}
});

//Arriba Composition
services.AddSingleton<ISecurityConfiguration>(serverConfig);
services.AddArribaServices(serverConfig);
Expand Down Expand Up @@ -139,19 +146,19 @@ private async Task Write(ArribaHttpContextRequest request, IResponse response, I
{
if (!context.Response.HasStarted)
{
context.Response.StatusCode = 500;
context.Response.StatusCode = 500;

if (responseBody.CanWrite)
{
using (var failureWriter = new StreamWriter(responseBody))
if (responseBody.CanWrite)
{
var message = String.Format("ERROR: Content writer {0} for content type {1} failed with exception {2}", writer.GetType(), writer.ContentType, writeException.GetType().Name);
await failureWriter.WriteAsync(message);
using (var failureWriter = new StreamWriter(responseBody))
{
var message = String.Format("ERROR: Content writer {0} for content type {1} failed with exception {2}", writer.GetType(), writer.ContentType, writeException.GetType().Name);
await failureWriter.WriteAsync(message);
}
}
}
}
}
}

response.Dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Arriba/Arriba.Test/Arriba.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Adapters\Arriba.Adapter.Configuration\Arriba.Adapter.Configuration.csproj" />
Expand Down

0 comments on commit 106cd82

Please sign in to comment.