autodesk-platform-services / aps-sdk-net

The official APS SDK for .NET.
https://www.nuget.org/profiles/AutodeskPlatformServices.SDK
Apache License 2.0
19 stars 12 forks source link

FolderContentsData not converting to JSON #107

Open tylerwarner33 opened 2 weeks ago

tylerwarner33 commented 2 weeks ago

The Autodesk.DataManagement.Model.FolderContents result is returning correctly when I use this method:

public async Task<FolderContents> GetFolderContentsDataByIdAsync(string projectId, string folderId, List<FilterType> filterType = null)
{
    ThreeLeggedToken token = await _accThreeLeggedTokensService.GetThreeLeggedTokenAsync();
    FolderContents folderContents = await APSClientHelper.DataManagementClient.GetFolderContentsAsync(
        projectId: projectId,
        folderId: folderId,
        accessToken: token.AccessToken,
        filterType: filterType);

    return folderContents;
}

As shown here: image image

However, FolderContents.Data (FolderContentsData) is not converting to JSON & therefore is not showing up in the response.

image

This was working in this previous version vs the current version.

Nuget package versions currently being used:

<PackageReference Include="Autodesk.Authentication" Version="2.0.0-beta4" />
<PackageReference Include="Autodesk.Construction.AccountAdmin" Version="2.0.0-beta" />
<PackageReference Include="Autodesk.DataManagement" Version="2.0.0-beta4" />
<PackageReference Include="Autodesk.Oss" Version="2.0.0-beta2" />
Arrotech commented 1 week ago

Hi @tylerwarner33 ,

Look at the following snippet of code, how to cast folderContents.Data as FolderData or ItemData. Here is the link to the sample take a look at GetFolderContentsAsync method.

Let me know if this helps

` public async Task GetFolderContentsAsync() { List filter_type = new List { FilterType.Items, FilterType.Folders };

    FolderContents folderContents = await dataManagementClient.GetFolderContentsAsync(projectId: project_id, folderId: folder_id, filterType: filter_type);
    List<IFolderContentsData> folderContentsData = folderContents.Data;
    foreach (var current in folderContentsData)
    {
        if (current is FolderData folder)
        {
            Console.WriteLine(folder.Id);
            Console.WriteLine(folder.Type);
            Console.WriteLine(folder.Relationships.Parent.Data.Type);
        }
        else if (current is ItemData item)
        {
            Console.WriteLine(item.Id);
            Console.WriteLine(item.Type);
        }
    }
}
`
tylerwarner33 commented 1 week ago

Hello @Arrotech, thank you, I did see that sample. It is helpful for being able to cast & use the data within the code.

But, is there a way for the data from the http response (image 1, includes data) to be passed to the JSON response (image 2, doesn't include data)?

image image

Arrotech commented 1 week ago

Hi @tylerwarner33 ,

At the moment I would say, no. You have to cast as FolderData or ItemData to access their data. This issue is noted and will be fixed.

Let me know what is not working for you (the data you can't access) so that we can help.

Thanks for reporting.

sajith-subramanian commented 1 week ago

Hi @tylerwarner33 - not sure I follow the issue completely. In the previous version, we had an issue where Foldercontents.Data would not return ItemData correctly. Since FolderContents can contain both FolderData & ItemData, in the new version we are now returning an Interface which needs to be cast and their data accessed. Let me know if I am missing something.

tylerwarner33 commented 1 week ago

Hello @sajith-subramanian, maybe the last version wasn't working exactly right with both the FolderData & ItemData.

The issue I'm having with this version is when the FolderContents object is returned via an endpoint (a controller response in this case), the IFolderContentsData is not converting to JSON. So the "data" object in the JSON (images shown in the original post) is showing the correct number of items (FolderData & ItemData) in the array, but they are all empty [ {}, {}, {}, {}, {}, {}, {} ].

All of the data is there in the code, but not in the controller response (images shown in the original post).

The FolderContents class is using this data annotation [JsonConverter(typeof(FolderContentsDataConverter))] for the conversion which is coming from the custom converter class FolderContentsDataConverter.

Let me know if you are getting a different result.

sajith-subramanian commented 6 days ago

Thanks for the details @tylerwarner33 . We will log this for further investigation.