-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 DynamicJson type #12843
Add DynamicJson type #12843
Changes from all commits
b6fc0a1
4b0ea31
89ebb3f
848ac93
1d5f123
4cfa31e
f133095
05eb10d
99507ce
fab111c
b2b1ba0
65349a2
b6f4983
639d5f9
5fbc4ce
6d8f927
dbca343
8616cc6
18c1dbd
ee8b195
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,62 @@ public readonly partial struct BinaryData | |
public override string ToString() { throw null; } | ||
public string ToString(System.Text.Encoding encoding) { throw null; } | ||
} | ||
public partial class DynamicJson : System.Dynamic.IDynamicMetaObjectProvider | ||
{ | ||
public DynamicJson(string json) { } | ||
public DynamicJson(System.Text.Json.JsonElement element) { } | ||
public Azure.Core.DynamicJson this[int arrayIndex] { get { throw null; } set { } } | ||
public Azure.Core.DynamicJson this[string propertyName] { get { throw null; } set { } } | ||
public static Azure.Core.DynamicJson Array() { throw null; } | ||
public static Azure.Core.DynamicJson Array(params Azure.Core.DynamicJson[] values) { throw null; } | ||
public static Azure.Core.DynamicJson Array(System.Collections.Generic.IEnumerable<Azure.Core.DynamicJson> values) { throw null; } | ||
public static Azure.Core.DynamicJson Create(System.Text.Json.JsonElement element) { throw null; } | ||
public System.Threading.Tasks.Task<T> DeserializeAsync<T>(Azure.Core.ObjectSerializer serializer) { throw null; } | ||
public T Deserialize<T>(Azure.Core.ObjectSerializer serializer) { throw null; } | ||
public T Deserialize<T>(System.Text.Json.JsonSerializerOptions? options = null) { throw null; } | ||
public System.Collections.Generic.IEnumerable<Azure.Core.DynamicJson> EnumerateArray() { throw null; } | ||
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Azure.Core.DynamicJson>> EnumerateObject() { throw null; } | ||
public int GetArrayLength() { throw null; } | ||
public bool GetBoolean() { throw null; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this convert the current value to a boolean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was purposefully trying to mirror JsonElement: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonelement?view=netcore-3.1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wasn't really expecting that. When I see this API, I wonder why we don't just add a couple of extension methods to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type can't be focused just on objects, services like digitaltwins support taking arbitrary JSON so the root can be an object or an array maybe even a primitive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And maybe we're trying to solve too much here? Maybe we should tell folks if you want to use primitives or arrays with DigitalTwins that you need to work with raw JSON elements. I don't think I'd want to use this type as it exists right now for Search because it's way too general and I think would confuse what's already a tricky part of the Search API. |
||
public double GetDouble() { throw null; } | ||
public float GetFloat() { throw null; } | ||
public int GetIn32() { throw null; } | ||
public long GetLong() { throw null; } | ||
public Azure.Core.DynamicJson GetProperty(string name) { throw null; } | ||
public string? GetString() { throw null; } | ||
public static Azure.Core.DynamicJson Object() { throw null; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the signature, I don't really know what this API does. Should this just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Any idea how to name the one that creates an array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public static Azure.Core.DynamicJson Object(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Azure.Core.DynamicJson>> values) { throw null; } | ||
public static explicit operator bool (Azure.Core.DynamicJson json) { throw null; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would love a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would also require us to have a factory func so the child DynamicJson objects we create are of the right type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and I'd like a virtual one of those as well please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you get an object nested into array via SearchDocument? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do that when parsing JSON. But if you just set a property, we leave your object type and let the JSON serializer deal with it when turning it back into JSON. |
||
public static explicit operator double (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator int (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator long (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator bool? (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator double? (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator int? (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator long? (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator float? (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator float (Azure.Core.DynamicJson json) { throw null; } | ||
public static explicit operator string (Azure.Core.DynamicJson json) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (bool value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (double value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (int value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (long value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (bool? value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (double? value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (int? value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (long? value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (float? value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (float value) { throw null; } | ||
public static implicit operator Azure.Core.DynamicJson (string? value) { throw null; } | ||
public static Azure.Core.DynamicJson Parse(string json) { throw null; } | ||
public static System.Threading.Tasks.Task<Azure.Core.DynamicJson> SerializeAsync<T>(T value, Azure.Core.ObjectSerializer serializer) { throw null; } | ||
public static Azure.Core.DynamicJson Serialize<T>(T value, Azure.Core.ObjectSerializer serializer) { throw null; } | ||
public static Azure.Core.DynamicJson Serialize<T>(T value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } | ||
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; } | ||
public System.Text.Json.JsonElement ToJsonElement() { throw null; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand. Serialize is a static method that takes an object and turns it into DJ. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sorry, should have said |
||
public override string ToString() { throw null; } | ||
public void WriteTo(System.Text.Json.Utf8JsonWriter writer) { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not feeling strong about it. I was trying to have a lot of interop with S.T.J. |
||
} | ||
public partial class JsonObjectSerializer : Azure.Core.ObjectSerializer | ||
{ | ||
public JsonObjectSerializer() { } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also implement
IDictionary
sooner than later because I think it'll help force some of the naming choices below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you feel strongly about having IDictionary and why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's such a well known, easy to use thing. This is getting to be a pretty hefty API at this point and if I'm trying to get a quick job done, seeing IDictionary may let me shortcut all the rest of it. All of https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.idictionary-2?view=netcore-3.1#extension-methods as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem with implementing IDictionary<string, DJ> is that I would also need to implement IList if the current value is an array. Then we get 2 IEnumerable interfaces on the same object and that's a bit weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're jamming an object and an array and primitives into the same type. It's already weird. 😄