microsoftgraph / msgraph-beta-sdk-dotnet

The Microsoft Graph Client Beta Library for .NET supports the Microsoft Graph /beta endpoint. (preview)
Other
95 stars 32 forks source link

Graph SDK V5: MobileAppContentFile.Serialize does not serialize read-only properties #823

Closed DCourtel closed 5 months ago

DCourtel commented 6 months ago

Since v5.68, the Serialize method of the MobileAppContentFile class does not serialize properties marked as read-only.

v5.67: image

v5.68: image

Is there a reason for that, or is it a bug? That breaks my unit tests.

Thanks.

andrueastman commented 5 months ago

Thanks for raising this @DCourtel

Any chance you can confirm if these properties can be sent over to the graph API? At the moment these properties are not serialized due the metadata used to generating the SDK describing them as read-only and thus should not be serialized to be sent over wire to the API.

Image

DCourtel commented 5 months ago

For people who encounter the same issue, this is a workaround: Provide value for the OnStartObjectSerialization property of the JsonSerializationWriter class:

using var _serializationWriter = new JsonSerializationWriter()
{
    OnStartObjectSerialization = new Action<IParsable, ISerializationWriter>(OnStartObjectSerialization),
};

And define the content of the Action as:

private static void OnStartObjectSerialization(IParsable value, ISerializationWriter writer)
{
    switch (value)
    {
        case MobileAppContentFile mobileAppContentFile:
            writer.WriteStringValue("azureStorageUri", mobileAppContentFile.AzureStorageUri);
            writer.WriteDateTimeOffsetValue("azureStorageUriExpirationDateTime", mobileAppContentFile.AzureStorageUriExpirationDateTime);
            writer.WriteDateTimeOffsetValue("createdDateTime", mobileAppContentFile.CreatedDateTime);
            writer.WriteBoolValue("isCommitted", mobileAppContentFile.IsCommitted);
            break;

        default:
            break;
    }
}
microsoft-github-policy-service[bot] commented 5 months ago