Skip to content

Commit

Permalink
Use System.Text.Json instead of JSON.NET in TypedRest.CommandLine
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Sep 30, 2023
1 parent 2178979 commit 67b256c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/TypedRest.CommandLine/Commands/EndpointCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json;
using TypedRest.CommandLine.IO;
using TypedRest.Endpoints;

Expand Down Expand Up @@ -60,6 +60,6 @@ protected virtual Task ExecuteInnerAsync(IReadOnlyList<string> args, Cancellatio
protected virtual T Input<T>(IReadOnlyList<string> args)
=> ((args.Count == 0)
? Console.Read<T>()
: JsonConvert.DeserializeObject<T>(args[0]))
: JsonSerializer.Deserialize<T>(args[0]))
?? throw new InvalidOperationException($"Expected {typeof(T)} but got null as input");
}
2 changes: 1 addition & 1 deletion src/TypedRest.CommandLine/Executor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json;
using TypedRest.CommandLine.Commands;
using TypedRest.Endpoints;

Expand Down
6 changes: 3 additions & 3 deletions src/TypedRest.CommandLine/IO/JsonConsole.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json;

namespace TypedRest.CommandLine.IO;

Expand All @@ -8,7 +8,7 @@ namespace TypedRest.CommandLine.IO;
public class JsonConsole : IConsole
{
public T? Read<T>()
=> JsonConvert.DeserializeObject<T>(Console.ReadLine() ?? throw new EndOfStreamException());
=> JsonSerializer.Deserialize<T>(Console.ReadLine() ?? throw new EndOfStreamException());

public string Read(string prompt)
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public void Write(object? output)
bool hasCustomToString = output.GetType().GetMethod(nameof(ToString))?.DeclaringType != typeof(object);
Console.WriteLine(hasCustomToString
? output.ToString()
: JsonConvert.SerializeObject(output, Formatting.Indented));
: JsonSerializer.Serialize(output, options: new() {WriteIndented = true}));
}

public void WriteError(string output)
Expand Down

0 comments on commit 67b256c

Please sign in to comment.