You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
System.Text.Json is not yet supported or used by the library (see #388), and as these generic JsonObject/JsonNode types usually require special handling rather than being treated as plain objects I don't believe that fixing the constructor issue would solve your issue.
You should be able to use dynamic/DynamicObject as the document type to handle unspecified structures. Alternatively there is also an implementation for using Newtonsoft
I did read through that issue. My main intent was to point out the constructor constraint causes issues. Unclear if this is intended / expected for constructors with optional parameters.
publicrecordFoo{//Would also fail?publicFoo(object?optional=null){}}
Is there a mechanism to receive Document as a byte array or a value that has not been deserialized? The intent is to save the initial deserialization cost. Should I create a separate issue?
Yes the constructor issue is valid, will need to see how it compares in scope/effort/priority wise against the fact we intend to throw away the current JSON serialisation and move to System.Text.Json in the future.
The way to skip all deserialisation is to use the generic http methods, using BytesResponse or StringResponse like so:
varresp=awaitclient.Http.PostAsync<BytesResponse>($"/{IndexName}/_search",
r =>r.SerializableBody(newSearchDescriptor<object>().Query(q =>q.MatchAll()).Size(20)));varbytes=resp.Body;
What is the bug?
Deserialization Cannot Handle Types with Constructors with Optional Parameters
Specifically,
new JsonObject()
is valid but fatals the deserialziation code. The result is we cannot deserialize to a JsonObjectHow can one reproduce the bug?
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.
The text was updated successfully, but these errors were encountered: