Skip to content

Conversation

RonAmihai
Copy link

@RonAmihai RonAmihai commented Sep 28, 2025

Allows passing custom (non-strongly typed in PostCursorOptions) options for PostCursorAsync.

This is a native implementation that does not handle duplicates between the strongly typed properties and the additional options. For example, if FullCount is included in the additional options, it will appear twice in the serialized JSON—first with the strongly typed value and again with the value from the additional properties dictionary.

Clarification: I personally need either that feature or the ForceOneShardAttributeValue support feature PR to support the forceOneShardAttributeValue option. I've created both approaches for your convenience, but both will work for me.

/// Entries are serialized at the same level as known properties (flattened).
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalOptions { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid putting a direct dependency on Newtonsoft.Json in the models. In theory other serialization options are available (e.g. System.Text.Json).

I wonder if this same could be achieved by sub-classing PostCursorOptions in client code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested your suggestion and it indeed works. For example, given the following:

using System.Collections.Generic;
using Newtonsoft.Json;

namespace ArangoDBNetStandard.CursorApi.Models
{
    public class ExtendedPostCursorOptions : PostCursorOptions
    {
        [JsonExtensionData]
        public IDictionary<string, object> AdditionalOptions { get; set; }
    }
}

The given test passes as expected:

[Fact]
public void Serialize_ShouldIncludeAdditionalOptions_WhenSerializingPostCursorOptions()
{
    var body = new PostCursorBody
    {
        Options = new ExtendedPostCursorOptions
        {
            FullCount = true,
            AdditionalOptions = new Dictionary<string, object>
            {
                ["fullCount"] = false,
                ["customFlag"] = false,
                ["oneShardAttributeValue"] = "tenant-123"
            }
        }
    };

    var serialization = new JsonNetApiClientSerialization();
    byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
        useCamelCasePropertyNames: true, ignoreNullValues: true));
    string jsonString = Encoding.UTF8.GetString(jsonBytes);

    // Ensure custom additional options are present
    Assert.Contains("\"customFlag\":false", jsonString);
    Assert.Matches("\"fullCount\":true.*\"fullCount\":false", jsonString);
    Assert.Contains("\"oneShardAttributeValue\":\"tenant-123\"", jsonString);

    // Ensure the AdditionalOptions property itself is not present
    Assert.DoesNotContain("\"additionalOptions\"", jsonString);
}

I'm closing the PR because this solution is enough for additional options.
It's worth noting that in the options class summary, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants