Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,31 @@ public override void Write(Utf8JsonWriter writer, TValue value, JsonSerializerOp

foreach (KeyValuePair<string, object?> variable in value.Parameters)
{
writer.WritePropertyName(variable.Key);
writer.WriteRawValue(JsonSerializer.Serialize(variable.Value, options));
if (variable.Value != null && variable.Value.GetType().IsGenericType && variable.Value.GetType().GetGenericTypeDefinition() == typeof(List<>))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great if there could be test cases for various scenarios here. Looks like maybe this unit test is meant to cover this functionality and could be expanded?

https://github.com/enjin/platform-csharp-sdk/blob/master/src/Enjin.Platform.Sdk/Enjin.Platform.Sdk.Tests/Unit/Json/GraphQlParameterJsonConverterTest.cs

{
var arrayOfParams = (List<IGraphQlParameter>) variable.Value;
writer.WritePropertyName(variable.Key);

foreach (var graphQlParameter in arrayOfParams)
{
writer.WriteStartArray();
writer.WriteStartObject();

foreach (KeyValuePair<string, object?> parameter in graphQlParameter.Parameters)
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably doesn't work if there are nested arrays. I don't know if that ever happens in Enjin schemas though so maybe that is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I will make a recursive function though I wonder if there isn't another way, I mean this whole function is called recursively already and it goes inside each the objects and the objects of ojects and decodes them fine. Only for arrays it seems to fail, so I wonder if this can't be fixed in another way, I will give another thought tomorrow.

{
writer.WritePropertyName(parameter.Key);
writer.WriteRawValue(JsonSerializer.Serialize(parameter.Value, options));
}

writer.WriteEndObject();
writer.WriteEndArray();
}
}
else
{
writer.WritePropertyName(variable.Key);
writer.WriteRawValue(JsonSerializer.Serialize(variable.Value, options));
}
}

writer.WriteEndObject();
Expand Down