-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json
Milestone
Description
Consider this coding snippet of JSON.NET outlined by @robertmclaws:
public async Task<bool> SomeMethod([FromBody] JObject data)
{
var model = data.ToObject<SomeObject>();
}Today, you can't do this with System.Text.Json. I propose we add APIs so that you can write this:
public async Task<bool> SomeMethod([FromBody] JsonElement data)
{
var model = data.Deserialize<SomeObject>();
}API Proposal
namespace System.Text.Json
{
public static partial class JsonSerializer
{
+ public static TValue? Deserialize<TValue>(this JsonDocument document, JsonSerializerOptions? options = null);
+ public static object? Deserialize(this JsonDocument document, Type returnType, JsonSerializerOptions? options = null);
+ public static TValue? Deserialize<TValue>(this JsonDocument document, JsonTypeInfo<TValue> jsonTypeInfo);
+ public static object? Deserialize(this JsonDocument document, Type returnType, JsonSerializerContext context);
+ public static JsonDocument SerializeToDocument<TValue>(TValue value, JsonSerializerOptions? options = null);
+ public static JsonDocument SerializeToDocument(object? value, Type inputType, JsonSerializerOptions? options = null);
+ public static JsonDocument SerializeToDocument<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo);
+ public static JsonDocument SerializeToDocument(object? value, Type inputType, JsonSerializerContext context);
+ public static TValue? Deserialize<TValue>(this JsonElement element, JsonSerializerOptions? options = null);
+ public static TValue? Deserialize<TValue>(this JsonElement element, JsonTypeInfo<TValue> jsonTypeInfo);
+ public static object? Deserialize(this JsonElement element, Type returnType, JsonSerializerOptions? options = null);
+ public static object? Deserialize(this JsonElement element, Type returnType, JsonSerializerContext context);
+ public static JsonElement SerializeToElement<TValue>(TValue value, JsonSerializerOptions? options = null);
+ public static JsonElement SerializeToElement(object? value, Type inputType, JsonSerializerOptions? options = null);
+ public static JsonElement SerializeToElement<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo);
+ public static JsonElement SerializeToElement(object? value, Type inputType, JsonSerializerContext context);
+ public static TValue? Deserialize<TValue>(this JsonNode node, JsonSerializerOptions? options = null);
+ public static TValue? Deserialize<TValue>(this JsonNode node, JsonTypeInfo<TValue> jsonTypeInfo);
+ public static object? Deserialize(this JsonNode node, Type returnType, JsonSerializerOptions? options = null);
+ public static object? Deserialize(this JsonNode node, Type returnType, JsonSerializerContext context);
+ public static JsonNode? SerializeToNode<TValue>(TValue value, JsonSerializerOptions? options = null);
+ public static JsonNode? SerializeToNode(object? value, Type inputType, JsonSerializerOptions? options = null);
+ public static JsonNode? SerializeToNode<TValue>(TValue value, JsonTypeInfo<TValue> jsonTypeInfo);
+ public static JsonNode? SerializeToNode(object? value, Type inputType, JsonSerializerContext context);
}
}robertmclaws, isijoc, rynowak, martinzima, gbellini79 and 119 moreengilas, Mrxx99 and AraHaanbryanhitc, jlorich, TAGC, xsoheilalizadeh, Havret and 13 moreMrxx99 and AraHaan
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json