Skip to content

Commit 373954a

Browse files
authored
Remove DynamicData name mapping APIs (Azure#36005)
* Considering DynamicDataNameMapping * Remove name mapping APIs * pr fb
1 parent ad49f21 commit 373954a

18 files changed

+116
-437
lines changed

sdk/cognitivelanguage/Azure.AI.Language.Conversations/tests/ConversationAnalysisClientLiveTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task AnalyzeConversation()
4545
Assert.IsNotNull(response);
4646

4747
// deserialize
48-
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
48+
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson();
4949
Assert.IsNotNull(conversationalTaskResult);
5050

5151
// assert - prediction type
@@ -91,7 +91,7 @@ public async Task AnalyzeConversation_Orchestration_Conversation()
9191
Assert.IsNotNull(response);
9292

9393
// deserialize
94-
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
94+
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson();
9595
Assert.IsNotNull(conversationalTaskResult);
9696

9797
// assert - prediction type
@@ -148,7 +148,7 @@ public async Task AnalyzeConversation_Orchestration_Luis()
148148
Assert.IsNotNull(response);
149149

150150
// deserialize
151-
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
151+
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson();
152152
Assert.IsNotNull(conversationalTaskResult);
153153

154154
// assert - prediction type
@@ -200,7 +200,7 @@ public async Task AnalyzeConversation_Orchestration_QuestionAnswering()
200200
Assert.IsNotNull(response);
201201

202202
// deserialize
203-
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
203+
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson();
204204
Assert.IsNotNull(conversationalTaskResult);
205205

206206
// assert - prediction type
@@ -255,7 +255,7 @@ public async Task SupportsAadAuthentication()
255255

256256
Response response = await client.AnalyzeConversationAsync(RequestContent.Create(data));
257257

258-
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
258+
dynamic conversationalTaskResult = response.Content.ToDynamicFromJson();
259259
Assert.That((string)conversationalTaskResult.Result.Prediction.TopIntent, Is.EqualTo("Send"));
260260
}
261261

@@ -321,7 +321,7 @@ public async Task AnalyzeConversation_ConversationSummarization()
321321

322322
Operation<BinaryData> analyzeConversationOperation = await Client.AnalyzeConversationAsync(WaitUntil.Completed, RequestContent.Create(data));
323323

324-
dynamic jobResults = analyzeConversationOperation.Value.ToDynamicFromJson(DynamicDataOptions.Default);
324+
dynamic jobResults = analyzeConversationOperation.Value.ToDynamicFromJson();
325325
Assert.NotNull(jobResults);
326326

327327
foreach (dynamic analyzeConversationSummarization in jobResults.Tasks.Items)
@@ -405,7 +405,7 @@ public async Task AnalyzeConversation_ConversationPII_TextInput()
405405

406406
Operation<BinaryData> analyzeConversationOperation = await Client.AnalyzeConversationAsync(WaitUntil.Completed, RequestContent.Create(data));
407407

408-
dynamic jobResults = analyzeConversationOperation.Value.ToDynamicFromJson(DynamicDataOptions.Default);
408+
dynamic jobResults = analyzeConversationOperation.Value.ToDynamicFromJson();
409409
Assert.NotNull(jobResults);
410410

411411
foreach (dynamic analyzeConversationPIIResult in jobResults.Tasks.Items)
@@ -569,7 +569,7 @@ public async Task AnalyzeConversation_ConversationPII_TranscriptInput()
569569

570570
Operation<BinaryData> analyzeConversationOperation = await Client.AnalyzeConversationAsync(WaitUntil.Completed, RequestContent.Create(data));
571571

572-
dynamic jobResults = analyzeConversationOperation.Value.ToDynamicFromJson(DynamicDataOptions.Default);
572+
dynamic jobResults = analyzeConversationOperation.Value.ToDynamicFromJson();
573573
Assert.NotNull(jobResults);
574574

575575
foreach (dynamic result in jobResults.Tasks.Items)

sdk/core/Azure.Core/api/Azure.Core.net461.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
1818
public static partial class AzureCoreExtensions
1919
{
2020
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
21-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Dynamic.DynamicDataNameMapping nameMapping) { throw null; }
22-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.DynamicDataOptions options) { throw null; }
2321
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2422
public static object? ToObjectFromJson(this System.BinaryData data) { throw null; }
2523
public static T? ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -46,12 +44,6 @@ public AzureSasCredential(string signature) { }
4644
public string Signature { get { throw null; } }
4745
public void Update(string signature) { }
4846
}
49-
public partial class DynamicDataOptions
50-
{
51-
public static readonly Azure.DynamicDataOptions Default;
52-
public DynamicDataOptions() { }
53-
public Azure.Core.Dynamic.DynamicDataNameMapping NameMapping { get { throw null; } set { } }
54-
}
5547
[System.FlagsAttribute]
5648
public enum ErrorOptions
5749
{
@@ -811,12 +803,6 @@ public void Dispose() { }
811803
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
812804
public override string ToString() { throw null; }
813805
}
814-
public enum DynamicDataNameMapping
815-
{
816-
None = 0,
817-
PascalCaseGetters = 1,
818-
PascalCaseGettersCamelCaseSetters = 2,
819-
}
820806
}
821807
namespace Azure.Core.Extensions
822808
{

sdk/core/Azure.Core/api/Azure.Core.net5.0.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
1818
public static partial class AzureCoreExtensions
1919
{
2020
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
21-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Dynamic.DynamicDataNameMapping nameMapping) { throw null; }
22-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.DynamicDataOptions options) { throw null; }
2321
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2422
public static object? ToObjectFromJson(this System.BinaryData data) { throw null; }
2523
public static T? ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -46,12 +44,6 @@ public AzureSasCredential(string signature) { }
4644
public string Signature { get { throw null; } }
4745
public void Update(string signature) { }
4846
}
49-
public partial class DynamicDataOptions
50-
{
51-
public static readonly Azure.DynamicDataOptions Default;
52-
public DynamicDataOptions() { }
53-
public Azure.Core.Dynamic.DynamicDataNameMapping NameMapping { get { throw null; } set { } }
54-
}
5547
[System.FlagsAttribute]
5648
public enum ErrorOptions
5749
{
@@ -811,12 +803,6 @@ public void Dispose() { }
811803
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
812804
public override string ToString() { throw null; }
813805
}
814-
public enum DynamicDataNameMapping
815-
{
816-
None = 0,
817-
PascalCaseGetters = 1,
818-
PascalCaseGettersCamelCaseSetters = 2,
819-
}
820806
}
821807
namespace Azure.Core.Extensions
822808
{

sdk/core/Azure.Core/api/Azure.Core.net6.0.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
1818
public static partial class AzureCoreExtensions
1919
{
2020
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
21-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Dynamic.DynamicDataNameMapping nameMapping) { throw null; }
22-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.DynamicDataOptions options) { throw null; }
2321
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2422
public static object? ToObjectFromJson(this System.BinaryData data) { throw null; }
2523
public static T? ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -46,12 +44,6 @@ public AzureSasCredential(string signature) { }
4644
public string Signature { get { throw null; } }
4745
public void Update(string signature) { }
4846
}
49-
public partial class DynamicDataOptions
50-
{
51-
public static readonly Azure.DynamicDataOptions Default;
52-
public DynamicDataOptions() { }
53-
public Azure.Core.Dynamic.DynamicDataNameMapping NameMapping { get { throw null; } set { } }
54-
}
5547
[System.FlagsAttribute]
5648
public enum ErrorOptions
5749
{
@@ -811,12 +803,6 @@ public void Dispose() { }
811803
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
812804
public override string ToString() { throw null; }
813805
}
814-
public enum DynamicDataNameMapping
815-
{
816-
None = 0,
817-
PascalCaseGetters = 1,
818-
PascalCaseGettersCamelCaseSetters = 2,
819-
}
820806
}
821807
namespace Azure.Core.Extensions
822808
{

sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
1818
public static partial class AzureCoreExtensions
1919
{
2020
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
21-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Dynamic.DynamicDataNameMapping nameMapping) { throw null; }
22-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.DynamicDataOptions options) { throw null; }
2321
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2422
public static object? ToObjectFromJson(this System.BinaryData data) { throw null; }
2523
public static T? ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -46,12 +44,6 @@ public AzureSasCredential(string signature) { }
4644
public string Signature { get { throw null; } }
4745
public void Update(string signature) { }
4846
}
49-
public partial class DynamicDataOptions
50-
{
51-
public static readonly Azure.DynamicDataOptions Default;
52-
public DynamicDataOptions() { }
53-
public Azure.Core.Dynamic.DynamicDataNameMapping NameMapping { get { throw null; } set { } }
54-
}
5547
[System.FlagsAttribute]
5648
public enum ErrorOptions
5749
{
@@ -811,12 +803,6 @@ public void Dispose() { }
811803
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
812804
public override string ToString() { throw null; }
813805
}
814-
public enum DynamicDataNameMapping
815-
{
816-
None = 0,
817-
PascalCaseGetters = 1,
818-
PascalCaseGettersCamelCaseSetters = 2,
819-
}
820806
}
821807
namespace Azure.Core.Extensions
822808
{

sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ protected AsyncPageable(System.Threading.CancellationToken cancellationToken) {
1818
public static partial class AzureCoreExtensions
1919
{
2020
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json) { throw null; }
21-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.Core.Dynamic.DynamicDataNameMapping nameMapping) { throw null; }
22-
public static dynamic ToDynamicFromJson(this System.BinaryData utf8Json, Azure.DynamicDataOptions options) { throw null; }
2321
public static System.Threading.Tasks.ValueTask<T?> ToObjectAsync<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2422
public static object? ToObjectFromJson(this System.BinaryData data) { throw null; }
2523
public static T? ToObject<T>(this System.BinaryData data, Azure.Core.Serialization.ObjectSerializer serializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -46,12 +44,6 @@ public AzureSasCredential(string signature) { }
4644
public string Signature { get { throw null; } }
4745
public void Update(string signature) { }
4846
}
49-
public partial class DynamicDataOptions
50-
{
51-
public static readonly Azure.DynamicDataOptions Default;
52-
public DynamicDataOptions() { }
53-
public Azure.Core.Dynamic.DynamicDataNameMapping NameMapping { get { throw null; } set { } }
54-
}
5547
[System.FlagsAttribute]
5648
public enum ErrorOptions
5749
{
@@ -811,12 +803,6 @@ public void Dispose() { }
811803
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
812804
public override string ToString() { throw null; }
813805
}
814-
public enum DynamicDataNameMapping
815-
{
816-
None = 0,
817-
PascalCaseGetters = 1,
818-
PascalCaseGettersCamelCaseSetters = 2,
819-
}
820806
}
821807
namespace Azure.Core.Extensions
822808
{

sdk/core/Azure.Core/samples/DynamicContent.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ JSON members are read using dynamic property access.
2020
```C# Snippet:AzureCoreGetDynamicJsonProperty
2121
Response response = client.GetWidget();
2222
dynamic widget = response.Content.ToDynamicFromJson();
23-
string name = widget.name;
23+
string name = widget.Name;
2424
```
2525

2626
### Set a JSON property
@@ -30,11 +30,11 @@ JSON members can be set on the dynamic object.
3030
```C# Snippet:AzureCoreSetDynamicJsonProperty
3131
Response response = client.GetWidget();
3232
dynamic widget = response.Content.ToDynamicFromJson();
33-
widget.name = "New Name";
33+
widget.Name = "New Name";
3434
client.SetWidget(RequestContent.Create(widget));
3535
```
3636

37-
### Access an array value
37+
### Get or set array values
3838

3939
JSON array values are accessed using array indexers. The `Length` property returns the number of elements in a JSON array.
4040

@@ -43,9 +43,9 @@ Response response = client.GetWidget();
4343
dynamic widget = response.Content.ToDynamicFromJson();
4444

4545
// JSON is `{ "values" : [1, 2, 3] }`
46-
if (widget.values.Length > 0)
46+
if (widget.Values.Length > 0)
4747
{
48-
int value = widget.values[0];
48+
int value = widget.Values[0];
4949
}
5050
```
5151

@@ -60,9 +60,9 @@ dynamic widget = response.Content.ToDynamicFromJson();
6060
// JSON is `{ "details" : { "color" : "blue", "size" : "small" } }`
6161
6262
// Check whether optional property is present
63-
if (widget.details != null)
63+
if (widget.Details != null)
6464
{
65-
string color = widget.details.color;
65+
string color = widget.Details.Color;
6666
}
6767
```
6868

@@ -75,7 +75,7 @@ Response response = client.GetWidget();
7575
dynamic widget = response.Content.ToDynamicFromJson();
7676

7777
// JSON is `{ "details" : { "color" : "blue", "size" : "small" } }`
78-
foreach (dynamic property in widget.details)
78+
foreach (dynamic property in widget.Details)
7979
{
8080
Console.WriteLine($"Widget has property {property.Name}='{property.Value}'.");
8181
}
@@ -93,27 +93,13 @@ dynamic widget = response.Content.ToDynamicFromJson();
9393
string id = widget["$id"];
9494
```
9595

96-
### Working with Azure values
97-
98-
When working with JSON from Azure services, you can learn what properties are available in the JSON response content from the REST API documentation for the service, examples in the protocol method documentation, or by expanding the [Dynamic View](https://learn.microsoft.com/visualstudio/debugger/watch-and-quickwatch-windows) in Visual Studio.
99-
100-
```C# Snippet:AzureCoreUseDynamicDataDefaults
101-
Response response = client.GetWidget();
102-
dynamic widget = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
103-
string id = widget.Id;
104-
widget.Name = "New Name";
105-
client.SetWidget(RequestContent.Create(widget));
106-
```
107-
108-
If no parameter is passed to `ToDynamicFromJson()`, properties names must exactly match the member names in the JSON content. Passing `DynamicDataOptions.Default` will enable properties to be accessed using PascalCase property names, and will write any added properties with camelCase names.
109-
11096
### Cast to a POCO type
11197

11298
Dynamic JSON objects can be cast to CLR types using the cast operator.
11399

114100
```C# Snippet:AzureCoreCastDynamicJsonToPOCO
115101
Response response = client.GetWidget();
116-
dynamic content = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
102+
dynamic content = response.Content.ToDynamicFromJson();
117103

118104
// JSON is `{ "id" : "123", "name" : "Widget" }`
119105
Widget widget = (Widget)content;
@@ -127,7 +113,19 @@ public class Widget
127113
}
128114
```
129115

130-
Passing `DynamicDataOptions.Default` will deserialize the type from JSON with case-insensitive property names.
116+
### Working with Azure values
117+
118+
When working with JSON from Azure services, you can learn what properties are available in the JSON response content from the REST API documentation for the service, examples in the protocol method documentation, or by expanding the [Dynamic View](https://learn.microsoft.com/visualstudio/debugger/watch-and-quickwatch-windows) in Visual Studio.
119+
120+
To behave as much as possible like Azure SDK model types, `DynamicData` allows JSON members to be accessed using PascalCase property names, and will write any added properties with camelCase names. If there is a need to bypass these name mappings, JSON members can be accessed with exact strings using property indexers.
121+
122+
```C# Snippet:AzureCoreSetPropertyWithoutCaseMapping
123+
Response response = client.GetWidget();
124+
dynamic widget = response.Content.ToDynamicFromJson();
125+
126+
widget.Details["IPAddress"] = "127.0.0.1";
127+
// JSON is `{ "details" : { "IPAddress" : "127.0.0.1" } }`
128+
```
131129

132130
## Setting RequestContent
133131

@@ -160,7 +158,7 @@ To make this common case easier to implement, Dynamic JSON is mutable. This all
160158

161159
```C# Snippet:AzureCoreRoundTripDynamicJson
162160
Response response = client.GetWidget();
163-
dynamic widget = response.Content.ToDynamicFromJson(DynamicDataOptions.Default);
161+
dynamic widget = response.Content.ToDynamicFromJson();
164162
widget.Name = "New Name";
165163
client.SetWidget(RequestContent.Create(widget));
166164
```

sdk/core/Azure.Core/samples/ProtocolMethods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ JSON properties can also be accessed using a dynamic layer.
123123
```C# Snippet:AzureCoreGetDynamicJsonProperty
124124
Response response = client.GetWidget();
125125
dynamic widget = response.Content.ToDynamicFromJson();
126-
string name = widget.name;
126+
string name = widget.Name;
127127
```
128128

129129
## Configuration And Customization

sdk/core/Azure.Core/samples/Response.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ If a service method does not return `Response<T>`, JSON content can be accessed
4343
```C# Snippet:AzureCoreGetDynamicJsonProperty
4444
Response response = client.GetWidget();
4545
dynamic widget = response.Content.ToDynamicFromJson();
46-
string name = widget.name;
46+
string name = widget.Name;
4747
```
4848

4949
See [dynamic content samples](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/DynamicContent.md) for more details.

0 commit comments

Comments
 (0)