0

I have a cross-platform Xamarin.Forms app that uses Json.Net to serialize and deserialize a class JMessage, which was taken from another question on the site. The class looks like this:

    public class JMessage
    {
        public Type Type { get; set; }
        public JToken Value { get; set; }

        public static JMessage FromValue<T>(T value)
        {
            return new JMessage { Type = typeof(T), Value = JToken.FromObject(value) };
        }

        public static string Serialize(JMessage message)
        {
            return JToken.FromObject(message).ToString();
        }

        public static JMessage Deserialize(string data)
        {
            return JToken.Parse(data).ToObject<JMessage>();
        }
    }

Everything is fine and dandy in the UWP and iOS versions of the app and nothing breaks. However, the Android version only serializes the Value property and completely ignores the Type property, causing things to break when the JMessage is deserialized. For example:

{
    "Value":{
       serialized properties go here...
    }
}

This seems to be a bug that spans across all Android devices, as I've tested it on 3 different Android devices, plus an emulator. The JMessage used to serialize and deserialize just fine so I'm not entirely sure what's happening now. Any answers?

  • What build of Json.NET are you using? I don't think Newtonsoft provides a xamarin build. – dbc Jan 13 '18 at 23:02
  • @dbc I'm using 10.0.3, which I'm pretty sure is the latest stable. I also thought that they do provide Xamarin support? At least that's what they say on their [website.](https://www.newtonsoft.com/json) – octillerysnacker Jan 14 '18 at 00:13
  • Sorry my question wasn't clear enough. Is it one of the official Newtonsoft builds from https://www.nuget.org/packages/newtonsoft.json/ or from elsewhere? – dbc Jan 14 '18 at 03:09
  • Yes, it's from NuGet. – octillerysnacker Jan 14 '18 at 04:45

0 Answers0