PlayFab.SimpleJson seems to convert dictionary to a list of key value pairs, which causes deserialization error in AzureFunctions. I was always using Newtonsoft.Json.JsonConvert on my end and it worked fine.
Class definition:
public class Equipment
{
public EquipmentRarity rarity { get; set; }
public Dictionary<int, int> randomAffixes { get; set; } <- this field is incorrectly converted into a list
public Tuple<int, int> influenceAffix { get; }
public int equipmentId { get; }
public string itemInstanceId { get; set; }
public int equipmentLevel { get; }
public int dropGameNumber { get; }
}
Using JsonConvert (In Unity):
{"rarity":2,"randomAffixes":{"1":20,"8":20,"11":20},"equipmentId":1,"equipmentLevel":3,"equippedHeroId":0,"influenceAffix":null,"dropGameNumber":30,"itemInstanceId":"FakeInstanceIdPlaceholder","itemId":"Equipment","itemClass":0}.
Using SimpleJson (In Unity):
{"rarity":2,"randomAffixes":[{"Key":1,"Value":20},{"Key":8,"Value":20},{"Key":11,"Value":20}],"equipmentId":1,"equipmentLevel":3,"equippedHeroId":0,"influenceAffix":null,"dropGameNumber":30,"itemInstanceId":"FakeInstanceIdPlaceholder","itemId":"Equipment","itemClass":0}.
I have also tried changed my deserializer in Azure Function from (I changed < to - to avoid web formatting issue):
var context =
JsonConvert.DeserializeObject-FunctionExecutionContext-GrantUserCheatEquipmentRequest>>(
await req.ReadAsStringAsync());
To:
var context =
PlayFabSimpleJson.DeserializeObject-FunctionExecutionContext-GrantUserCheatEquipmentRequest>>(
await req.ReadAsStringAsync());
and lead to a weird error in PlayFabSimpleJson
[2023-01-11T06:12:37.783Z] Unexpected error calling GrantUserCheatEquipment. [Object reference not set to an instance of an object.]
at PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type)
[2023-01-11T06:12:37.784Z] at PlayFab.Json.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type)
[2023-01-11T06:12:37.785Z] at PlayFab.Json.PlayFabSimpleJson.DeserializeObject(String json, Type type, IJsonSerializerStrategy jsonSerializerStrategy)
[2023-01-11T06:12:37.787Z] at PlayFab.Json.PlayFabSimpleJson.DeserializeObject[T](String json)
[2023-01-11T06:12:37.789Z] at Kykystudio.FunctionApp.Functions.GrantUserCheatEquipment.Run(HttpRequest req, ILogger log) in H:\workspace\Unity\AutoCard\AutoCardAzure\Kykystudio.FunctionApp\Functions\GrantUserCheatEquipment.cs:line 30
Could you please help me out on this problem? I don't think Dictionary need to be converted into List, but if that is not changable, please let me know why I cannot use PlayFabSimpleJson in Azure Funtions.