Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
ref: Use System.Text.Json
Browse files Browse the repository at this point in the history
Not supporting [DataContract]
See dotnet/corefx#33115
  • Loading branch information
bruno-garcia committed Jun 16, 2019
1 parent a86e06b commit 8caa3a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion global.json
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.2.105"
"version": "3.0.100-preview6-012264"
}
}
4 changes: 2 additions & 2 deletions src/Sentry.Protocol/Sentry.Protocol.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard1.3;net46;net45</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;netstandard2.0;netstandard1.3;net45</TargetFrameworks>
<LangVersion>7.2</LangVersion>
<PackageId>Sentry.Protocol</PackageId>
<AssemblyName>Sentry.Protocol</AssemblyName>
Expand All @@ -15,7 +15,7 @@
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.0'">
<DefineConstants>HAS_VALUE_TUPLE;$(AdditionalConstants)</DefineConstants>
</PropertyGroup>

Expand Down
19 changes: 18 additions & 1 deletion test/Sentry.Protocol.Tests/JsonSerializer.cs
@@ -1,20 +1,37 @@
#if HAS_SYSTEM_JSON
using System.Text.Json.Serialization;
using Json = System.Text.Json.Serialization.JsonSerializer;
#else
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
#endif

namespace Sentry.Protocol.Tests
{
internal class JsonSerializer
{
#if HAS_SYSTEM_JSON

private static readonly JsonSerializerOptions Options = new JsonSerializerOptions()
{
IgnoreNullValues = true,
};

public static string SerializeObject<T>(T @object) => Json.ToString(@object, Options);
public static dynamic DeserializeObject(string json) => Json.Parse<dynamic>(json);
#else
private static readonly StringEnumConverter StringEnumConverter = new StringEnumConverter();

private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.None,
Converters = new[] { StringEnumConverter }
Converters = new[] {StringEnumConverter}
};

public static string SerializeObject<T>(T @object) => JsonConvert.SerializeObject(@object, Settings);
public static dynamic DeserializeObject(string json) => JsonConvert.DeserializeObject(json);
#endif
}
}
25 changes: 17 additions & 8 deletions test/Sentry.Protocol.Tests/Sentry.Protocol.Tests.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;netcoreapp2.1;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net45</TargetFrameworks>
</PropertyGroup>

Expand All @@ -10,23 +10,32 @@
<Reference Include="System.Threading.Tasks" />
<ProjectReference Include="../../src/Sentry.Protocol/Sentry.Protocol.csproj" Properties="TargetFramework=net45" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<DefineConstants>HAS_VALUE_TUPLE;$(AdditionalConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<ProjectReference Include="../../src/Sentry.Protocol/Sentry.Protocol.csproj" Properties="TargetFramework=netstandard1.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<ProjectReference Include="../../src/Sentry.Protocol/Sentry.Protocol.csproj" Properties="TargetFramework=netstandard2.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Condition="'$(TargetFramework)' != 'net45'" Version="3.1.0" />
<ProjectReference Include="../../src/Sentry.Protocol/Sentry.Protocol.csproj" Properties="TargetFramework=netstandard2.0" />
</ItemGroup>

<!--nca2.1 tests the NS2.0 version which has value tuples. nca2.0 tests ns1.3 which doesn't.-->
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
<DefineConstants>HAS_VALUE_TUPLE;$(AdditionalConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<PackageReference Include="System.Text.Json" Version="4.6.0-preview6.19303.8" />
<ProjectReference Include="../../src/Sentry.Protocol/Sentry.Protocol.csproj" Properties="TargetFramework=netcoreapp3.0" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<DefineConstants>HAS_VALUE_TUPLE;HAS_SYSTEM_JSON;$(AdditionalConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Condition="'$(TargetFramework)' != 'net45'" Version="3.1.0" />
</ItemGroup>
</Project>

0 comments on commit 8caa3a3

Please sign in to comment.