-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 BinaryData.ToDynamicFromJson() #53642
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsBackground and MotivationWe designed BinaryData as a simple one-stop shop converting data from and to binary data. This type is especially useful for the Azure SDK where many technologies store blobs of data but the consumer typically uses strings or JSON encoded data. We've recently added Proposed APInamespace System
{
public class BinaryData
{
public T ToDynamicFromJson<T>(JsonSerializerOptions? options = null);
}
} Usage ExamplesResponse response = client.SomeMethod("s1", 5, RequestContent.Create(model));
dynamic result = response.Content.ToDynamicFromJson();
Console.WriteLine(result.Baz); Alternative DesignsThe Azure SDK could define their own extension method, but that feels wrong. RisksNone; /cc @steveharter @layomia @KrzysztofCwalina
|
What is the |
This would also depend on a specific answer to the questions asked in #53195, yes? |
It should return dynamic, i.e. public dynamic ToDynamicFromJson() {
dynamic result = JsonNode.Parse(this.ToMemory());
return result;
} |
And the |
fixed above (i.e. removed T) I also removed the options. They are not used by JsonNode.Parse. We could add overloads to take the JsonNode.Parse options, but I don't think any of these make sense on when reading JSON. These are the JsonNode.Parse options: public struct JsonNodeOptions {
public bool PropertyNameCaseInsensitive { get; set; }
}
public struct JsonDocumentOptions {
public bool AllowTrailingCommas { get; set; }
public JsonCommentHandling CommentHandling { get; set; }
public int MaxDepth { get; set; }
} |
That's just me being dumb |
I think you forgot to hit save :-)
Hmm.... I thought we'd need at least the ability to change naming conventions but you probably also want support for converters and reference handling, no? |
I just fixed my sample, not yours :-)
I might be misunderstanding what the options do. I dont see how they support converters. Your API proposal takes serializer options, but the implementation of this method will use JsonNode.Parse, which does not take serializer options. |
Ah, I was misremembering. I thought namespace System
{
public class BinaryData
{
public dynamic ToDynamicFromJson(JsonNodeOptions? nodeOptions = default, JsonDocumentOptions documentOptions = default);
}
} Note: both @steveharter and @layomia are currently out, but they would have to take a look at this. |
Per discussion in #53195 about removing support for "dynamic", this API issue may be put on hold pending API discussion. |
Given that it's unclear whether or we're supporting |
I don't really understand how it could be "unclear". Imo, it's a must have for some architectures which need to be resilient and use dynamic to. |
The concern is that |
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsBackground and MotivationWe designed BinaryData as a simple one-stop shop converting data from and to binary data. This type is especially useful for the Azure SDK where many technologies store blobs of data but the consumer typically uses strings or JSON encoded data. We've recently added Proposed APInamespace System
{
public class BinaryData
{
public dynamic ToDynamicFromJson(JsonSerializerOptions? options = null);
}
} Usage ExamplesResponse response = client.SomeMethod("s1", 5, RequestContent.Create(model));
dynamic result = response.Content.ToDynamicFromJson();
Console.WriteLine(result.Baz); Alternative DesignsThe Azure SDK could define their own extension method, but that feels wrong. RisksNone; /cc @steveharter @layomia @KrzysztofCwalina
|
@jaredpar, any possibility of getting the "lightweight dynamic" feature in the next version of C#? i.e. a specially attributed indexer (string to dynamic map) that the compiler would call when dynamic properties are accessed. |
There is no concrete design for the said feature, only a series of discussion points. There is not universal agreement between the interested parties on exactly what properties the "lightweight dynamic" feature should have. |
With our main focus on cloud native, where we compete mostly against languages that are AOTed (not JITted) I don't see us investing more in
This sounds like a reasonable workaround.
If it was made AOT-friendly at the same time, it sounds like the proper solution that should be pursued. |
Background and Motivation
We designed BinaryData as a simple one-stop shop converting data from and to binary data. This type is especially useful for the Azure SDK where many technologies store blobs of data but the consumer typically uses strings or JSON encoded data.
We've recently added
JsonNode
for .NET 6 which includes the ability to treat a JSON object asdynamic
so that one can "dot" into the type without having to use the indexer syntax. The Azure SDK has asked me whether we could add a convenience method toBinaryData
to directly convert a blob to a dynamic object.Proposed API
Usage Examples
Alternative Designs
The Azure SDK could define their own extension method, but that feels wrong.
Risks
None;
BinaryData
already depends onSystem.Text.Json
. This new API doesn't change the dependency matrix./cc @steveharter @layomia @KrzysztofCwalina
The text was updated successfully, but these errors were encountered: