question

Canberk Soner avatar image
Canberk Soner asked

Exception when deserializing result of Admin API GetCatalogItems in Editor

I'm making an editor tool to update and read catalog items using Admin API. (this is necessary for various reasons).

Updating items:

public static void UpdateItem(ItemData data)
        {
            string titleId = PlayFabEditorDataService.SharedSettings.TitleId;
            string apiEndpoint = "https://" + titleId + PlayFabEditorHelper.TITLE_ENDPOINT;


            UpdateCatalogItemsRequest request = new UpdateCatalogItemsRequest()
            {
                Catalog = new List<CatalogItem>() { new CatalogItem(data) }
            };


            PlayFabEditorHttp.MakeApiCall<UpdateCatalogItemsRequest, UpdateCatalogItemsResult>("/Admin/UpdateCatalogItems", apiEndpoint, request, (UpdateCatalogItemsResponse) => { Debug.Log("UpdateItem SUCCESS."); }, (PlayFabError) => { Debug.Log("UpdateItem FAIL"); });
        }

This works without a problem. My ItemData is from another source and this allows me to parse it and update playfab catalog items.

Next, I would like to get the catalog items:

public static void GetItems()
        {
            string titleId = PlayFabEditorDataService.SharedSettings.TitleId;
            string apiEndpoint = "https://" + titleId + PlayFabEditorHelper.TITLE_ENDPOINT;


            GetCatalogItemsRequest request = new GetCatalogItemsRequest()
            {
                CatalogVersion = "MyCatalog"
            };
            
            PlayFabEditorHttp.MakeApiCall<GetCatalogItemsRequest, GetCatalogItemsResult>("/Admin/GetCatalogItems", apiEndpoint, request, OnCatalogItemsReceived, (PlayFabError) => { Debug.Log("Get Item FAIL"); });            
        }

Result object (I use the same catalog item in updateitem method, it works):

    public class GetCatalogItemsResult
    {
        public List<CatalogItem> Catalog { get; set; }
    }

public class CatalogItem
    {
        public string ItemId        { get; set; }
        public string ItemClass     { get; set; }
        public string DisplayName   { get; set; }
        public bool IsStackable     { get; set; }
        public string CustomData    { get; set; }
        public string[] Tags        { get; set; }
    }

However, GetItems throws a null exception:

NullReferenceException: Object reference not set to an instance of an object PlayFab.PfEditor.Json.PocoJsonSerializerStrategy.DeserializeObject (System.Object value, System.Type type) (at Assets/PlayFabEditorExtensions/Editor/Scripts/PlayFabEditorSDK/SimpleJson.cs:1450)

I tried removing the customdata field, still same exception.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image brendan commented ·

Can you provide the complete call stack, or just step into the call to see which specific call is resulting in the null reference?

0 Likes 0 ·
Canberk Soner avatar image Canberk Soner brendan commented ·

I did write the line and script throwing the exception.

You can find the exception log here: errorlog.txt

The json received from http request:

"{\"code\":200,\"status\":\"OK\",\"data\":{\"Catalog\":[{\"ItemId\":\"M468\",\"ItemClass\":\"Weapon\",\"CatalogVersion\":\"Cards\",\"DisplayName\":\"M468\",\"VirtualCurrencyPrices\":{},\"Tags\":[\"Assault\"],\"Consumable\":{},\"CanBecomeCharacter\":false,\"IsStackable\":true,\"IsTradable\":false,\"IsLimitedEdition\":false,\"InitialLimitedEditionCount\":0},{\"ItemId\":\"C5\",\"ItemClass\":\"Weapon\",\"CatalogVersion\":\"Cards\",\"DisplayName\":\"C5\",\"VirtualCurrencyPrices\":{},\"Tags\":[\"Grenade\"],\"Consumable\":{},\"CanBecomeCharacter\":false,\"IsStackable\":true,\"IsTradable\":false,\"IsLimitedEdition\":false,\"InitialLimitedEditionCount\":0}]}}"

What's strange is that I don't receive custom data when I make the call from editor, but the response includes custom data when I call using Postman.

0 Likes 0 ·
errorlog.txt (3.2 KiB)
brendan avatar image brendan Canberk Soner commented ·

What Title ID is this, so that we can have a look at the specifics of the setup?

0 Likes 0 ·
Show more comments

1 Answer

·
Canberk Soner avatar image
Canberk Soner answered

Update: Instead of using my class to deserialize the result, I've used the item class in PlayFab.ClientModels and it worked.

I have no idea why the custom class did not work, though, as its fields are the same except lacking certain fields, which usually does not break deserialization. But maybe SimpleJson does not allow that.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.