Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question DeserializationException..

Discussion in 'Cloud Code' started by KM6611, Mar 12, 2024.

  1. KM6611

    KM6611

    Joined:
    Jun 27, 2018
    Posts:
    15
    Calling CloudCode throws a DeserializationException.

    The strange thing is that ItemDataA does not throw a DeserializationException but ItemDataB does

    - DataClass A
    Code (CSharp):
    1. namespace MyGameData;
    2.  
    3. public class ItemDataA
    4. {
    5.     public int itemId;
    6.     public int count;
    7. }
    - DataClass B
    Code (CSharp):
    1. namespace MyGameData;
    2.  
    3. public class ItemDataB
    4. {
    5.     public int itemId;
    6.     public int count;
    7. }
    - CloudCode
    Code (CSharp):
    1.     [CloudCodeFunction("GetData")]
    2.     public async Task<ItemDataA> ResponseTest(IExecutionContext context, IGameApiClient gameApiClient)
    3.     {
    4.         return new ItemDataA() { itemId = 1000 , count = 10 };
    5.     }
    - UnityCode
    Code (CSharp):
    1.  public async void GetItem()
    2.     {
    3.         try
    4.         {
    5.             var result = await CloudCodeService.Instance.CallModuleEndpointAsync<ItemDataA>("GamePlayModule", "GetData");
    6.         }
    7.         catch (CloudCodeException e)
    8.         {
    9.     Debug.Log(e.ToString());
    10.         }
    11.     }

    In the case of the ItemDataA class, it runs normally, but

    When running with the ItemDataB class, a DeserializationException occurs.

    However, both run normally in the Unity Editor.

    When building and running APK, DeserializationException occurs only in ItemDataB.


    -Error
    Unity.Services.CloudCode.Internal.Http.DeserializationException: Unable to find a constructor to use for type MyGameData.ItemDataB. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'count', line 1, position 9.

    I don't know the cause

    Is there anything I can try?
     
    Last edited: Mar 12, 2024
  2. samg-unity

    samg-unity

    Unity Technologies

    Joined:
    Mar 23, 2021
    Posts:
    50
    KM6611 likes this.