You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Ease a way of constructing JsonObject #54158
I want to create JSON from this record and query its Age property. Alas, JSON API doesn't have similar JsonObject.Create() which would accept an object. Also this doesn't work either:
Activity
eiriktsarpalis commentedon Jun 14, 2021
cc @steveharter
huoyaoyuan commentedon Jun 14, 2021
This would require reflection
steveharter commentedon Jul 26, 2021
This is covered by #31274. Specifically:
namespace System.Text.Json { public static partial class JsonSerializer { + 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); } }Example of deserialize node to object:
Example of serialize object to node: