Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Unable to serialise CallRecord types #217

Closed
cowlinb6 opened this issue Apr 29, 2024 · 5 comments
Closed

Unable to serialise CallRecord types #217

cowlinb6 opened this issue Apr 29, 2024 · 5 comments

Comments

@cowlinb6
Copy link

Similar issue to #212 but with CallRecord types.

When attempting to serialise a CallRecord type:

var callRecord = await _graphServiceClient.Communications.CallRecords[id]
    .GetAsync((config) =>
    {
        config.QueryParameters.Expand = new string[] { "sessions($expand=segments)" };
    });
var raw = KiotaJsonSerializer.SerializeAsString<CallRecord>(callRecord);

This fails with the error below:

System.InvalidOperationException: AdditionalData can not be null
   at Microsoft.Graph.Models.Entity.get_AdditionalData()
   at Microsoft.Graph.Models.Entity.Serialize(ISerializationWriter writer)
   at Microsoft.Graph.Models.CallRecords.CallRecord.Serialize(ISerializationWriter writer)
   at Microsoft.Kiota.Serialization.Json.JsonSerializationWriter.WriteObjectValue[T](String key, T value, IParsable[] additionalValuesToMerge)
   at Microsoft.Kiota.Abstractions.Serialization.KiotaSerializer.SerializeAsStream[T](String contentType, T value)
   at Microsoft.Kiota.Abstractions.Serialization.KiotaSerializer.SerializeAsString[T](String contentType, T value)
   at Microsoft.Kiota.Abstractions.Serialization.KiotaJsonSerializer.SerializeAsString[T](T value)
   at TeamsPbxTest.GraphClient.GetCallRecord(String id) in C:\Users\Ben\source\code\TeamsPbxTest\TeamsPbxTest\GraphClient.cs:line 177

How should I be serialising this type?

@github-project-automation github-project-automation bot moved this to Todo 📃 in Kiota Apr 29, 2024
@andrueastman
Copy link
Member

Thanks for raising this @cowlinb6

I suspect the error you're seeing is related to microsoft/kiota#4514. However, AdditionalData should be automatically initialized when the object is created in the constructor. Do you still get the error if you add the line below before serializing?

callRecord.AdditionalData = new();

@cowlinb6
Copy link
Author

If I add this:

callRecord.AdditionalData = new Dictionary<string, object>();
var raw = KiotaJsonSerializer.SerializeAsString<CallRecord>(callRecord);

Then it fixes the exception but I only get this in the response:

image

@andrueastman
Copy link
Member

andrueastman commented Apr 29, 2024

This is probably because of the backingStore. We're looking to enhance the KiotaJsonSerializer to have the option to set the flag for you.

Does the following work for you?

var callRecord = await _graphServiceClient.Communications.CallRecords[id]
    .GetAsync((config) =>
    {
        config.QueryParameters.Expand = new string[] { "sessions($expand=segments)" };
    });
callRecord.BackingStore.InitializationCompleted = false;
var raw = KiotaJsonSerializer.SerializeAsString<CallRecord>(callRecord);

@cowlinb6
Copy link
Author

Yes this does work.

Thanks @andrueastman for the quick response on this

@andrueastman
Copy link
Member

Thanks for confirming. We'll close this one for now.

We're looking to enhance the KiotaJsonSerializer to have the option to set the flag for you.

Currently tracked for all languages via microsoft/kiota-java#1131

@github-project-automation github-project-automation bot moved this from Todo 📃 to Done ✔️ in Kiota Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants