-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JsonTypeInfo overloads to System.Memory.Data #54979
Comments
Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-memory Issue DetailsBackground and MotivationIn 6.0, we have added APIs to System.Text.Json and System.Net.Http.Json that take a JsonTypeInfo or JsonSerializerContext. See #1568 for the reasons and advantages of these overloads. We have very thin wrapper APIs in System.Memory.Data around JsonSerializer, however these APIs weren't updated for JsonTypeInfo overloads. We should add them to get the same advantages as listed above. Proposed APInamespace System
{
public partial class BinaryData
{
// exisitng APIs
public BinaryData(object? jsonSerializable, System.Text.Json.JsonSerializerOptions? options = null, System.Type? type = null) { }
public static System.BinaryData FromObjectAsJson<T>(T jsonSerializable, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
public T? ToObjectFromJson<T>(System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
// new proposed APIs
+ public BinaryData(object? jsonSerializable, System.Text.Json.Serialization.JsonSerializerContext context, System.Type? type = null) { }
+ public static System.BinaryData FromObjectAsJson<T>(T jsonSerializable, System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo) { throw null; }
+ public T? ToObjectFromJson<T>(System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> jsonTypeInfo) { throw null; }
}
} Usage Examplesvar myObject = new MyType();
var binaryData = new BinaryData(myObject, JsonContext.Default);
// --- or ---
var binaryData = BinaryData.FromObjectAsJson(myObject, JsonContext.Default.MyType);
var myObject2 = binaryData.ToObjectFromJson(JsonContext.Default.MyType); Alternative DesignsN/A RisksNone cc @layomia @JoshLove-msft @KrzysztofCwalina
|
The current APIs require unreferenced code, since they call into JsonSerializer without providing JsonTypeInfo. dotnet#54979 is logged to add "trim compatible" APIs here.
The current APIs require unreferenced code, since they call into JsonSerializer without providing JsonTypeInfo. #54979 is logged to add "trim compatible" APIs here.
Given there hasn't been any feedback on this. I'm going to move it to ready for review. |
namespace System;
public partial class BinaryData
{
// Existing APIs
// public BinaryData(object? jsonSerializable, JsonSerializerOptions? options = null, Type? type = null);
// public static BinaryData FromObjectAsJson<T>(T jsonSerializable, JsonSerializerOptions? options = null);
// public T? ToObjectFromJson<T>(JsonSerializerOptions? options = null);
// New APIs
public BinaryData(object? jsonSerializable, JsonSerializerContext context, Type? type = null);
public static BinaryData FromObjectAsJson<T>(T jsonSerializable, JsonTypeInfo<T> jsonTypeInfo);
public T? ToObjectFromJson<T>(JsonTypeInfo<T> jsonTypeInfo);
} |
@eerhardt should this be labeled 'up for grabs' |
Hi guys I'd like to take this one up. |
Will System.Memory.Data remain a NetStandard 2.0 package after this change? |
Yes, System.Memory.Data still supports netstandard2.0 after this change:
The |
Background and Motivation
In 6.0, we have added APIs to System.Text.Json and System.Net.Http.Json that take a JsonTypeInfo or JsonSerializerContext. See #1568 for the reasons and advantages of these overloads.
We have very thin wrapper APIs in System.Memory.Data around JsonSerializer, however these APIs weren't updated for JsonTypeInfo overloads. We should add them to get the same advantages as listed above.
Proposed API
Usage Examples
Alternative Designs
N/A
Risks
None
cc @layomia @JoshLove-msft @KrzysztofCwalina
The text was updated successfully, but these errors were encountered: