- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8
 
Serialize array of dictionaries correctly #9
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 all commits
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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -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<>)) | ||
| { | ||
| 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) | ||
| 
         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. 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. 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. 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(); | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
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