opensearch-net icon indicating copy to clipboard operation
opensearch-net copied to clipboard

[BUG] Deserialization Cannot Handle Types with Constructors with Optional Parameters

Open JCKortlang opened this issue 7 months ago • 3 comments

What is the bug?

Deserialization Cannot Handle Types with Constructors with Optional Parameters

System.Exception: Cannot create an instance of System.Text.Json.Nodes.JsonObject because it does not have a public constructor accepting IDictionary<System.String,System.Text.Json.Nodes.JsonNode> argument or a public parameterless constructor
   at OpenSearch.Client.InterfaceGenericDictionaryResolver.DictionaryFormatterHelper.GetFormatter(Type t)
   at OpenSearch.Client.InterfaceGenericDictionaryResolver.FormatterCache`1..cctor()

Specifically, new JsonObject() is valid but fatals the deserialziation code. The result is we cannot deserialize to a JsonObject

    //Given
    public JsonObject(JsonNodeOptions? options = null)
      : base(options)
    {
    }

How can one reproduce the bug?

using System.Text.Json.Nodes
return await openSearchClient.SearchAsync<JsonObject>(searchRequest);

What is the expected behavior?

I expect to be able to deserialize to standard .NET Json abstractions

What is your host/environment?

MacOS 13.6.7 (22G720)

Do you have any screenshots?

No

Do you have any additional context?

I am attempting to deserialize a request to an index alias that contains multiple types. Since the Search interface does not support this, I need to deserialize the response to a more generic type. Ideally one of the standard and existing Json abstractions.

JCKortlang avatar Jul 23 '24 00:07 JCKortlang