Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Microsoft.DotNet.Interactive.Formatting
public class DataDictionaryConverter : JsonConverter<System.Collections.Generic.IDictionary<System.String,System.Object>>
.ctor()
public System.Collections.Generic.IDictionary<System.String,System.Object> Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
public static class Destructurer
public static IDestructurer GetOrCreate(System.Type type)
public class Destructurer<T>, IDestructurer<T>, IDestructurer
Expand Down Expand Up @@ -132,11 +129,6 @@ Microsoft.DotNet.Interactive.Formatting
public System.Boolean Format(T instance, FormatContext context)
public abstract class ITypeFormatterSource
public System.Collections.Generic.IEnumerable<ITypeFormatter> CreateTypeFormatters()
public abstract class JsonConverter<T> : JsonConverter<T>
protected System.Void EnsureStartArray(System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert)
protected System.Void EnsureStartObject(System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert)
protected System.Void OnWrite(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
public static class JsonExtensions
public static Microsoft.DotNet.Interactive.Formatting.TabularData.TabularDataResource ToTabularDataResource()
public static Microsoft.DotNet.Interactive.Formatting.TabularData.TabularDataResource ToTabularDataResource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ Microsoft.DotNet.Interactive
.ctor(Microsoft.DotNet.Interactive.Connection.KernelClientBase client = null)
protected Func<TCommand,KernelInvocationContext,System.Threading.Tasks.Task> CreateDefaultHandlerForCommandType<TCommand>()
public System.Threading.Tasks.Task HandleAsync(Microsoft.DotNet.Interactive.Commands.SendValue command, KernelInvocationContext context)
public abstract class JsonConverter<T> : JsonConverter<T>
protected System.Void EnsureStartObject(System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert)
protected System.Void OnWrite(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
public abstract class Kernel, IKernelCommandHandler<Microsoft.DotNet.Interactive.Commands.RequestKernelInfo>, System.IDisposable
public static Kernel Current { get;}
public static Kernel Root { get;}
Expand Down Expand Up @@ -451,14 +447,6 @@ Microsoft.DotNet.Interactive.Connection
public abstract class ConnectKernelDirective<TCommand> : Microsoft.DotNet.Interactive.Directives.KernelActionDirective
public System.String ConnectedKernelDescription { get; set;}
public System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Microsoft.DotNet.Interactive.Kernel>> ConnectKernelsAsync(TCommand connectCommand, Microsoft.DotNet.Interactive.KernelInvocationContext context)
public class DirectoryInfoJsonConverter : Microsoft.DotNet.Interactive.JsonConverter<System.IO.DirectoryInfo>
.ctor()
public System.IO.DirectoryInfo Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, System.IO.DirectoryInfo value, System.Text.Json.JsonSerializerOptions options)
public class FileInfoJsonConverter : Microsoft.DotNet.Interactive.JsonConverter<System.IO.FileInfo>
.ctor()
public System.IO.FileInfo Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, System.IO.FileInfo value, System.Text.Json.JsonSerializerOptions options)
public abstract class IKernelCommandAndEventReceiver, System.IObservable<CommandOrEvent>
public abstract class IKernelCommandAndEventSender
public System.Uri RemoteHostUri { get;}
Expand Down Expand Up @@ -505,10 +493,6 @@ Microsoft.DotNet.Interactive.Connection
.ctor(T command)
public T Command { get;}
public System.String CommandType { get;}
public class KernelDirectiveConverter : Microsoft.DotNet.Interactive.JsonConverter<Microsoft.DotNet.Interactive.Directives.KernelDirective>
.ctor()
public Microsoft.DotNet.Interactive.Directives.KernelDirective Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, Microsoft.DotNet.Interactive.Directives.KernelDirective value, System.Text.Json.JsonSerializerOptions options)
public abstract class KernelEventEnvelope, IKernelEventEnvelope
public static IKernelEventEnvelope Create(Microsoft.DotNet.Interactive.Events.KernelEvent event)
public static IKernelEventEnvelope Deserialize(System.String json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ Microsoft.DotNet.Interactive.Jupyter.Protocol
.ctor(System.String commId, System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object> data = null)
public System.String CommId { get;}
public System.Collections.Generic.IReadOnlyDictionary<System.String,System.Object> Data { get;}
public class CommCloseConverter : Microsoft.DotNet.Interactive.JsonConverter<CommClose>
.ctor()
public CommClose Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, CommClose value, System.Text.Json.JsonSerializerOptions options)
public class CommInfoReply : ReplyMessage
.ctor(System.Collections.Generic.IReadOnlyDictionary<System.String,CommTarget> comms)
public System.Collections.Generic.IReadOnlyDictionary<System.String,CommTarget> Comms { get;}
Expand Down Expand Up @@ -300,10 +296,6 @@ Microsoft.DotNet.Interactive.Jupyter.Protocol
public class HistoryReply : ReplyMessage
.ctor(System.Collections.Generic.IReadOnlyList<HistoryElement> history = null)
public System.Collections.Generic.IReadOnlyList<HistoryElement> History { get;}
public class HistoryReplyConverter : Microsoft.DotNet.Interactive.JsonConverter<HistoryReply>
.ctor()
public HistoryReply Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, HistoryReply value, System.Text.Json.JsonSerializerOptions options)
public class HistoryRequest : RequestMessage
.ctor(System.Int32 session, System.String accessType = range, System.Int32 start = 0, System.Int32 stop = 0, System.Int32 n = 0, System.String pattern = null, System.Boolean unique = False, System.Boolean raw = False, System.Boolean output = False)
public System.String AccessType { get;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;

namespace Microsoft.DotNet.Interactive.Documents.Json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;

namespace Microsoft.DotNet.Interactive.Documents.Json;

Expand Down
31 changes: 0 additions & 31 deletions src/Microsoft.DotNet.Interactive.Documents/JsonConverter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.Utility;

namespace Microsoft.DotNet.Interactive.Documents.Jupyter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Documents.Utility;
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.Utility;

namespace Microsoft.DotNet.Interactive.Documents.Jupyter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Documents.Utility;
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.Utility;

namespace Microsoft.DotNet.Interactive.Documents.Jupyter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;

namespace Microsoft.DotNet.Interactive.Documents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;

namespace Microsoft.DotNet.Interactive.Documents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Microsoft.DotNet.Interactive.Formatting\JsonConverter.cs" Link="Utility\JsonConverter.cs" />
<Compile Include="..\Microsoft.DotNet.Interactive\Utility\DictionaryExtensions.cs" Link="Utility\DictionaryExtensions.cs" />
<Compile Include="..\Microsoft.DotNet.Interactive\Utility\IOExtensions.cs" Link="Utility\IOExtensions.cs" />
<Compile Include="..\Microsoft.DotNet.Interactive\Utility\NullableAttributes.cs" Link="Utility\NullableAttributes.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.DotNet.Interactive.Formatting;

public class DataDictionaryConverter : JsonConverter<IDictionary<string, object>>
internal class DataDictionaryConverter : JsonConverter<IDictionary<string, object>>
{
public override IDictionary<string, object> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Expand Down
9 changes: 5 additions & 4 deletions src/Microsoft.DotNet.Interactive.Formatting/JsonConverter.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable
using System;
using System.Text.Json;

namespace Microsoft.DotNet.Interactive.Formatting;

public abstract class JsonConverter<T> : System.Text.Json.Serialization.JsonConverter<T>
internal abstract class JsonConverter<T> : System.Text.Json.Serialization.JsonConverter<T>
{
protected void EnsureStartObject(Utf8JsonReader reader, Type typeToConvert)
{
if (reader.TokenType != JsonTokenType.StartObject)
if (reader.TokenType is not JsonTokenType.StartObject)
{
throw new JsonException(
$"Cannot deserialize {typeToConvert.Name}, expecting {JsonTokenType.StartObject} but found {reader.TokenType}");
Expand All @@ -19,7 +20,7 @@ protected void EnsureStartObject(Utf8JsonReader reader, Type typeToConvert)

protected void EnsureStartArray(Utf8JsonReader reader, Type typeToConvert)
{
if (reader.TokenType != JsonTokenType.StartArray)
if (reader.TokenType is not JsonTokenType.StartArray)
{
throw new JsonException(
$"Cannot deserialize {typeToConvert.Name}, expecting {JsonTokenType.StartObject} but found {reader.TokenType}");
Expand All @@ -35,6 +36,6 @@ protected virtual void OnWrite(Utf8JsonWriter writer, T value, JsonSerializerOpt
{
var localOptions = new JsonSerializerOptions(options);
localOptions.Converters.Remove(this);
JsonSerializer.Serialize(writer, value, value.GetType(), localOptions);
JsonSerializer.Serialize(writer, value, value!.GetType(), localOptions);
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.DotNet.Interactive.Formatting;

namespace Recipes;

internal static class JsonSerializationExtensions
{
static JsonSerializationExtensions()
{
SerializerOptions =
new JsonSerializerOptions(JsonSerializerDefaults.General)
{
WriteIndented = false,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.AllowNamedFloatingPointLiterals,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
SerializerOptions.Converters.Add(new DataDictionaryConverter());
SerializerOptions.Converters.Add(new BareObjectConverter());
}

public static JsonSerializerOptions SerializerOptions { get; }

public static string ToJson(this object source) =>
JsonSerializer.Serialize(source, SerializerOptions);
JsonSerializer.Serialize(source, Microsoft.DotNet.Interactive.Connection.Serializer.JsonSerializerOptions);

public static T FromJsonTo<T>(this string json) =>
JsonSerializer.Deserialize<T>(json, SerializerOptions);

public static object FromJsonTo(this string json, Type type, JsonSerializerOptions options = null) =>
JsonSerializer.Deserialize(json, type, options?? SerializerOptions);
JsonSerializer.Deserialize<T>(json, Microsoft.DotNet.Interactive.Connection.Serializer.JsonSerializerOptions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;

namespace Microsoft.DotNet.Interactive.Jupyter.Messaging;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Recipes;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.RegularExpressions;
Expand All @@ -16,7 +15,7 @@ public static T DeserializeFromJsonString<T>(string source)
var ret = default(T);
if (!string.IsNullOrWhiteSpace(source) && !IsEmptyJson(source))
{
ret = JsonSerializer.Deserialize<T>(source, JsonSerializationExtensions.SerializerOptions);
ret = JsonSerializer.Deserialize<T>(source, Microsoft.DotNet.Interactive.Connection.Serializer.JsonSerializerOptions);
}
return ret;
}
Expand All @@ -34,7 +33,7 @@ private static Protocol.Message DeserializeMessageContentFromJsonString(string s
public static Message DeserializeMessage(string signature, string headerJson, string parentHeaderJson,
string metadataJson, string contentJson, IReadOnlyList<IReadOnlyList<byte>> identifiers, JsonSerializerOptions options = null)
{
var header = JsonSerializer.Deserialize<Header>(headerJson, options ?? JsonSerializationExtensions.SerializerOptions);
var header = JsonSerializer.Deserialize<Header>(headerJson, options ?? Microsoft.DotNet.Interactive.Connection.Serializer.JsonSerializerOptions);
var parentHeader = DeserializeFromJsonString<Header>(parentHeaderJson);
var metaData = MetadataExtensions.DeserializeMetadataFromJsonString(metadataJson);
var content = DeserializeMessageContentFromJsonString(contentJson, header.MessageType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Microsoft.DotNet.Interactive.Formatting\JsonConverter.cs" Link="Protocol\JsonConverter.cs" />
<Compile Include="..\Microsoft.DotNet.Interactive\Utility\InvocationContextExtensions.cs" Link="Utility\InvocationContextExtensions.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using Microsoft.DotNet.Interactive.Jupyter.Messaging;
using System;
using System.Text.Json;
using Microsoft.DotNet.Interactive.Formatting;

namespace Microsoft.DotNet.Interactive.Jupyter.Protocol;

public class CommCloseConverter : JsonConverter<CommClose>
internal class CommCloseConverter : JsonConverter<CommClose>
{
public override CommClose Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Expand Down
Loading