• Discuss all the things!

    146 Topics
    517 Posts

    @LEE-JONG-GUN,

    Hmm, unfortunately I don't believe you can set JsonReader to be able to use a converter. In this case you might want to continue using JsonConvert then.

    The first solution I shared where you deserialize & serialize the response to strip out the trailing .0 might be your option here. Additionally, you can also modify your local copy of BrainCloudComms.cs to do this for all responses in-case this situation pops up elsewhere. This will essentially replicate the same behaviour in BC 5.9.2 and older.

    If that's the route you take you can modify BrainCloudComms.cs in the HandleResponseBundle function on line 972 like so:

    private void HandleResponseBundle(string jsonData) { jsonData = jsonData.Trim(); if ((jsonData.StartsWith("{") && jsonData.EndsWith("}")) || (jsonData.StartsWith("[") && jsonData.EndsWith("]"))) { jsonData = JsonWriter.Serialize(JsonReader.Deserialize(jsonData)); // This will strip any leading .0 for int values, replicating the behaviour from 5.9.2 }

    We will have to look into if we should have this be an optional flag that can be enabled for compatibility... Do note though that this will mean that a lot of the memory and performance gains from 5.9.3 will be lost.

    There is another option though and that's to leverage JsonConverter πŸ˜ƒ

    Here's a script that should take floats/doubles during deserialization and convert them to an int. I modified it and tested it, I think it should work for this situation:

    using System; using Newtonsoft.Json; /// <summary> /// Converts JSON floating-point numbers (float/double) to int during deserialization. /// </summary> public class FloatToIntJsonConverter : JsonConverter<int> { public override int ReadJson(JsonReader reader, Type objectType, int existingValue, bool hasExistingValue, JsonSerializer serializer) { switch (reader.TokenType) { case JsonToken.Float: return Convert.ToInt32(Math.Round(Convert.ToDouble(reader.Value), MidpointRounding.AwayFromZero)); case JsonToken.Integer: return Convert.ToInt32(reader.Value); case JsonToken.String: string sVal = reader.Value?.ToString() ?? "0"; if (double.TryParse(sVal, out double parsed)) { return Convert.ToInt32(Math.Round(parsed, MidpointRounding.AwayFromZero)); } throw new JsonSerializationException($"Cannot deserialize string to int: {sVal}"); case JsonToken.Null: return 0; default: throw new JsonSerializationException($"Unexpected token when tryign to deserialize as int: {reader.TokenType}"); } } public override void WriteJson(JsonWriter writer, int value, JsonSerializer serializer) { writer.WriteValue(value); } }

    You can apply this to any specific problematic int like so:

    public class ScoreData { [JsonConverter(typeof(FloatToIntJsonConverter))] public int tier; }

    Of course you can also apply it globally, but that might be a bit riskier to do πŸ˜… Also note that this script will round floats/doubles to the nearest whole number so if you end up using it make sure to keep that in-mind (or feel free to modify it to suit your needs).

    Let us know if either of these work out for you!

  • Suggestions for improvements, new features, etc.

    41 Topics
    132 Posts

    Hi Francesco, thanks for the suggestion about the folder-level import/export feature. I will have our team review it. FYI, you could script the uploads using the SysPrepareUpload S2S API to avoid doing it manually through the portal.

  • Questions specific to particular APIs, libraries, etc.

    60 Topics
    250 Posts

    Thanks for confirming @peter !

  • General cloud code discussions...

    34 Topics
    143 Posts

    Yes, the link provided in that article is automatically updated. For your reference, here is the actual embedded link behind it:
    https://portalx.braincloudservers.com/dts/cloudcode_dts_files.zip

  • brainCloud's online learning tutorials and examples.

    3 Topics
    3 Posts

    brainCloud developers have just release several playable builds of our famous examples! See our cool features in action. Find them at https://getbraincloud.com/demos for Windows, Mac, online and mobile.

brainCloud 5 is alive!

brainCloud 5 features Portal-X (our next-gen portal), Integrated Forums (you found them), our new Bootcamp training videos, and more!

Join the discussion here!

brainCloud Bootcamp!
brainCloud's new video learning portal is now online! Go check out brainCloud BootCamp!

Need to report a defect?
Use the chat widget from the Design Portal - or send an email to support at getbraincloud.com. Thanks!