Autodesk-Forge / forge-api-dotnet-client

Forge .Net SDK: Provides .Net SDK to help you easily integrate Forge REST APIs into the application
https://www.nuget.org/packages/Autodesk.Forge/
Apache License 2.0
95 stars 70 forks source link

Getting Attributes from GetItem Api Call #102

Open ericjisaac opened 2 years ago

ericjisaac commented 2 years ago

Following the documentation for GetItem results in Exceptions: Exception when calling ItemsApi.GetItems: Cannot implicitly convert type 'Autodesk.Forge.Model.DynamicJsonResponse' to 'Autodesk.Forge.Model.Item'

Similar to #32.

No working way of getting the typed object was described as part of the resolution for #32 . Either the docs should be updated, or an appropriate way of using the typed objects should be specified.

I need the Item to get its Attributes. Using response.ToObject<Item> on API responses strips Attributes from the object. I can see that all the desired data is present in the DynamicJsonResponse.

Code:

 private Item? GetItem(string projectId, string fileId)
 {
            try
            {
                DynamicJsonResponse response = _itemsApi.GetItem(projectId, fileId);
                Item item = response.ToObject<Item>();
                return item;
            } 
            catch(Exception e)
            {
                Debug.Print("Exception when calling ItemsApi.GetItems: " + e.Message);
                return null;
            }
 }

This is using Forge v. 1.9.7 in Visual Studio 2022

ericjisaac commented 2 years ago

For the time being, I have a solution that just parses the JSON, but it seems like a waste if the ability to get the typed object is in fact implemented. Also, the fact that the ToObject<Item>() mostly works makes me unsure whether this is a bug or not (should Attributes be included?).

ericjisaac commented 2 years ago

After further tests, the return from GetFolderContents has a similar issue. The response JSON contains all expected data, but the SDK classes/objects obtained by following the examples in this repo (issues/documentation) are missing data (e.g. Attributes for each individual item). This is in a .NET 6 project.

rferreiraperez commented 1 year ago

After further tests, the return from GetFolderContents has a similar issue. The response JSON contains all expected data, but the SDK classes/objects obtained by following the examples in this repo (issues/documentation) are missing data (e.g. Attributes for each individual item). This is in a .NET 6 project.

I have the same problem, any solution? I'm using the latest version (1.9.7) and .NET 6 as well.