diff --git a/src/TypedRest.CommandLine/Commands/EndpointCommand.cs b/src/TypedRest.CommandLine/Commands/EndpointCommand.cs index 8233cdd3..a8819306 100644 --- a/src/TypedRest.CommandLine/Commands/EndpointCommand.cs +++ b/src/TypedRest.CommandLine/Commands/EndpointCommand.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; using TypedRest.CommandLine.IO; using TypedRest.Endpoints; @@ -60,6 +60,6 @@ protected virtual Task ExecuteInnerAsync(IReadOnlyList args, Cancellatio protected virtual T Input(IReadOnlyList args) => ((args.Count == 0) ? Console.Read() - : JsonConvert.DeserializeObject(args[0])) + : JsonSerializer.Deserialize(args[0])) ?? throw new InvalidOperationException($"Expected {typeof(T)} but got null as input"); } diff --git a/src/TypedRest.CommandLine/Executor.cs b/src/TypedRest.CommandLine/Executor.cs index 96db8520..8ee065bd 100644 --- a/src/TypedRest.CommandLine/Executor.cs +++ b/src/TypedRest.CommandLine/Executor.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; using TypedRest.CommandLine.Commands; using TypedRest.Endpoints; diff --git a/src/TypedRest.CommandLine/IO/JsonConsole.cs b/src/TypedRest.CommandLine/IO/JsonConsole.cs index c5f21915..8e1c06e6 100644 --- a/src/TypedRest.CommandLine/IO/JsonConsole.cs +++ b/src/TypedRest.CommandLine/IO/JsonConsole.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json; namespace TypedRest.CommandLine.IO; @@ -8,7 +8,7 @@ namespace TypedRest.CommandLine.IO; public class JsonConsole : IConsole { public T? Read() - => JsonConvert.DeserializeObject(Console.ReadLine() ?? throw new EndOfStreamException()); + => JsonSerializer.Deserialize(Console.ReadLine() ?? throw new EndOfStreamException()); public string Read(string prompt) { @@ -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)