-
Notifications
You must be signed in to change notification settings - Fork 34
Fixed dictionary item value serialization issue - Part 2 #445
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
Changes from 4 commits
3059678
b32f42c
e69c3a9
0e98898
e43e662
194010d
5ae3706
43cee7b
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 |
|---|---|---|
|
|
@@ -72,15 +72,18 @@ public virtual async Task<GetAllViewsResponse> GetAllViewsAsync( | |
| /// Create a new View | ||
| /// POST /_api/view | ||
| /// </summary> | ||
| /// <param name="body">The body of the request containing required properties.</param> | ||
| /// <param name="body">The body of the request containing required properties.</param> | ||
| /// <param name="serializationOptions">Custom serialization options to be used.</param> | ||
| /// <param name="token">A CancellationToken to observe while waiting for the task to complete or to cancel the task.</param> | ||
| /// <returns></returns> | ||
| public virtual async Task<ViewResponse> PostCreateViewAsync(ViewDetails body, | ||
| CancellationToken token = default) | ||
| public virtual async Task<ViewResponse> PostCreateViewAsync(ViewDetails body, ApiClientSerializationOptions serializationOptions = null, CancellationToken token = default) | ||
| { | ||
| string uri = _apiPath; | ||
| var content = GetContent(body, new ApiClientSerializationOptions(true, true)); | ||
| using (var response = await _transport.PostAsync(uri, content, token: token).ConfigureAwait(false)) | ||
| var content = GetContent(body, | ||
| serializationOptions ?? new ApiClientSerializationOptions( | ||
|
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 don't think Instead we should turn on the option, like so: 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 just noticed that you asked about this in your previous comment: #445 (comment) I missed that. From what I understand, the option should be hardcoded by us in the API method because we don't want to allow other options to be modified. I see the following mentioned on LinksProperties.IncludeAllFields: 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.
OK 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.
If
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. Setting 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 will take a closer look in the coming days. 👍 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. At a glance, some thoughts: What you did makes sense to me (adding a new method parameter Alternatives: We can allow specifying the dictionary options individually, letting us cover all cases. For example: add a new property in public class ApiClientSerializationOptions
{
/*...*/
/// <summary>
/// Whether dictionary values should be serialized with the same options
/// as normal objects.
/// </summary>
/// <remarks>
/// If false, you can use <see cref="DictionaryOptions"/>
/// to control individual options for dictionary serialization.
/// </remarks>
public bool ApplySerializationOptionsToDictionaryValues { get; set; }
/// <summary>
/// Serialization options to apply specifically to dictionary values.
/// </summary>
/// <remarks>
/// If <see cref="ApplySerializationOptionsToDictionaryValues"/> is true,
/// this property is ignored.
/// If <see cref="ApplySerializationOptionsToDictionaryValues"/> is false and
/// <see cref="DictionaryOptions"/> is null, then dictionary values are serialized
/// as provided (untouched).
/// </remarks>
public ApiClientSerializationOptions DictionaryOptions { get; set; }
}Perhaps create a new type for dictionary options: public interface ISerializationOptions // For convenience to have a source of truth for available options.
{
public bool UseCamelCasePropertyNames { get; set; }
public bool IgnoreNullValues { get; set; }
public bool IgnoreMissingMember { get; set; }
public bool UseStringEnumConversion { get; set; }
}
public class ApiClientSerializationOptions : ISerializationOptions
{
/*...*/
public bool ApplySerializationOptionsToDictionaryValues { get; set; }
public DictionaryValuesSerializationOptions DictionaryOptions { get; set; }
}
public class DictionaryValuesSerializationOptions : ISerializationOptions
{
/*...*/
}Maybe With this new property, we (as the library) can do the following inside var content = GetContent(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true,
ignoreNullValues: true,
DictionaryOptions: new DictionaryValuesSerializationOptions()
{
useCamelCasePropertyNames: true,
ignoreNullValues: IncludeAllFields // not sure if it makes sense
}));I don't know if this also covers advanced scenarios such as nesting of links, e.g. what happens when someone sends: new ViewDetails()
{
Links = new Dictionary<string, LinksProperties>()
{
["Files"] = new LinksProperties()
{
Fields = Dictionary<string, LinksProperties>()
{
["Properties"] = new LinksProperties()
{
/*...*/
}
}
}
}
}Not sure if this is even valid, I don't know enough about the view feature. Perhaps best to leave it to the caller like you did. 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 had another look and this approach could be used together with the parameter public virtual async Task<ViewResponse> PostCreateViewAsync(
ViewDetails body,
bool ignoreNullLinksAndFields = false,
CancellationToken token = default)
{
var content = GetContent(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true,
ignoreNullValues: true,
DictionaryOptions = new DictionaryValuesSerializationOptions
{
useCamelCasePropertyNames: true,
ignoreNullValues: ignoreNullLinksAndFields
}));
}Not blocker, just a thought. |
||
| useCamelCasePropertyNames: true, | ||
| ignoreNullValues: true)); | ||
| using (var response = await _transport.PostAsync(uri, content).ConfigureAwait(false)) | ||
| { | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.