Skip to content

Commit b090a0b

Browse files
committed
refactor(config): remove Newtonsoft.Json in favor of System.Text.Json
1 parent 5c70edc commit b090a0b

5 files changed

Lines changed: 14 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Remove `NoPartialFunctions` compiler workaround (#698) [@webwarrior-ws]
1515
- Add `SLNX` and `SLNF` format support and migrate to SLNX solution #723 [@xperiandri]\
1616
Remove `Ionide.ProjInfo.Sln` NuGet package dependency
17+
- Remove `Newtonsoft.Json` NuGet dependency #725 [@xperiandri]
1718

1819
## [0.24.2] - 2024-02-29
1920

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="17.14.8" />
2222
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.14.8" />
2323
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
24-
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
2524
<PackageVersion Include="NUnit" Version="3.14.0" />
2625
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
2726
<PackageVersion Include="System.Reactive" Version="6.0.1" />
27+
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
2828
</ItemGroup>
2929
</Project>

src/FSharpLint.Console/FSharpLint.Console.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<ItemGroup>
3030
<PackageReference Include="Argu" />
3131
<PackageReference Include="FSharp.Core" />
32-
<PackageReference Include="Newtonsoft.Json" />
3332
</ItemGroup>
3433

3534
<ItemGroup>

src/FSharpLint.Core/Application/Configuration.fs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module FSharpLint.Framework.Configuration
44
open System
55
open System.IO
66
open System.Reflection
7-
open Newtonsoft.Json
7+
open System.Text.Json
8+
open System.Text.Json.Serialization
89
open FSharpLint.Framework
910
open FSharpLint.Framework.Rules
1011
open FSharpLint.Framework.HintParser
@@ -15,40 +16,16 @@ let SettingsFileName = "fsharplint.json"
1516

1617
exception ConfigurationException of string
1718

18-
module FSharpJsonConverter =
19-
open Microsoft.FSharp.Reflection
20-
21-
type OptionConverter() =
22-
inherit JsonConverter()
23-
24-
override x.CanConvert(t) =
25-
t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<_ option>
26-
27-
override x.WriteJson(writer, value, serializer) =
28-
let value =
29-
if isNull value then null
30-
else
31-
let _,fields = FSharpValue.GetUnionFields(value, value.GetType())
32-
fields.[0]
33-
serializer.Serialize(writer, value)
34-
35-
override x.ReadJson(reader, t, _, serializer) =
36-
let innerType = t.GetGenericArguments().[0]
37-
let innerType =
38-
if innerType.IsValueType then (typedefof<Nullable<_>>).MakeGenericType([|innerType|])
39-
else innerType
40-
let value = serializer.Deserialize(reader, innerType)
41-
let cases = FSharpType.GetUnionCases(t)
42-
if isNull value then FSharpValue.MakeUnion(cases.[0], [||])
43-
else FSharpValue.MakeUnion(cases.[1], [|value|])
44-
45-
let private converters =
46-
[|
47-
OptionConverter() :> JsonConverter
48-
|]
19+
module internal FSharpJsonConverter =
4920

50-
let serializerSettings =
51-
JsonSerializerSettings(NullValueHandling = NullValueHandling.Ignore, Converters = converters)
21+
let jsonOptions =
22+
let options =
23+
JsonSerializerOptions(
24+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
25+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
26+
)
27+
options.Converters.Add(JsonStringEnumConverter())
28+
options
5229

5330
module IgnoreFiles =
5431

@@ -582,7 +559,7 @@ with
582559
/// Tries to parse the provided config text.
583560
let parseConfig (configText:string) =
584561
try
585-
JsonConvert.DeserializeObject<Configuration>(configText, FSharpJsonConverter.serializerSettings)
562+
JsonSerializer.Deserialize<Configuration>(configText, FSharpJsonConverter.jsonOptions)
586563
with
587564
| ex -> raise <| ConfigurationException $"Couldn't parse config, error=%s{ex.Message}"
588565

src/FSharpLint.Core/FSharpLint.Core.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
<PackageReference Include="Microsoft.Build.Tasks.Core" ExcludeAssets="runtime" />
152152
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="runtime" />
153153
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
154-
<PackageReference Include="Newtonsoft.Json" />
155154
</ItemGroup>
156155

157156
</Project>

0 commit comments

Comments
 (0)