-
Notifications
You must be signed in to change notification settings - Fork 33
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
JsonSerializationWriter.WriteNonParsableObjectValue does not support anonymous objects #306
Comments
In trying to work around this issue, it seems the problem is worse than I thought. The PR I submitted should work for custom non parseable classes but for dictionary should probably have it's own method. I will try to make a more extensive PR. |
Hi @greg-ww |
Hi @baywet thanks for getting back to me. Like I mentioned, I am setting AdditionalData on a type generated by Kiota. The original type for the property in question in our API is a dictionary of string to another model type which gets represented in the openAPI spec as
for which Kiota generates
I am not sure I understand why Kiota doesn't just use a dictionary of the same type as our models, given that the structure in the openAPI spec appears to be constrained enough to do so. But with things the way they are the only way to populate this type is to set AdditionalData, something the generated comments indicate is actively supported. So we set the values in additional data which is Dictionary<string, object>, but no type is provided by Kiota for the type described in the openAPI spec as "MyDictionaryValueType". Because we treat the code in the Kiota client folder as generated and rely on that to provide us the types we use interacting with our API the best and most convenient compromise is to set the values we want as an anonymous object as this is the closest thing to setting them on a generated type and by all indications from the serializer this is perfectly valid and functional (until you look at the JSON Kiota sends). Outside of my own personal use case, I feel like setting AdditionalData is a useful and valid way to set properties for a type that is either extremely flexible or cannot be fully defined in the openAPI spec. The options for values I tried to assign to it seemed perfectly intuitive, first an anonymous object, then I made a class to represent it, then I represented the type as a dictionary. If there are good reasons to not support these I would at least expect the serializer to return a proper error, preferably returning me some information about what types would be accepted. |
Thanks for the additional context here. |
Have you considered making the types that you pass as values of the additional properties implement IParsable instead? |
Yeah that's my next workaround, I only know I need to do that because I debugged into JsonSerializationWriter though. At minimum I'd expect an error if the types I tried to use are unsupported. |
This is probably a good situation for other cases. Can you tweak this exception message as part of your PR please? |
I was passing values into the AdditionalData property on the type generated in my Kiota client and I noticed that anonymous object values were being passed as empty objects.
From debugging I can see that here
kiota-dotnet/src/serialization/json/JsonSerializationWriter.cs
Line 447 in 42ea74e
No error is thrown, the properties just never show up. It's possible this affects other types but I only tested with anonymous objects.
The text was updated successfully, but these errors were encountered: