Search code examples
c#androidxamarinaws-sdklitjson

Extra garbage produced by LitJson serialization with AWS SDK for MonoAndroid10


When I run the following code in a windows console application referencing AWSSDK.Core.3.3.19.1\lib\net45\AWSSDK.Core.dll, I get nice output:

public class Person
{
   public string Name { get; set; }
   public int Age { get; set; }
   public DateTime Birthday { get; set; }
}

public static void PersonToJson()
{
   Person bill = new Person();

   bill.Name = "William Shakespeare";
   bill.Age = 51;
   bill.Birthday = new DateTime(1564, 4, 26);

   string json_bill = JsonMapper.ToJson(bill);

   Console.WriteLine(json_bill);
}

The output (formatting added) is:

{  
   "Name":"William Shakespeare",
   "Age":51,
   "Birthday":"04/26/1564 00:00:00"
}

But when I run the same code referencing AWSSDK.Core.3.3.19.1\lib\MonoAndroid10\AWSSDK.Core.dll, I get different results:

EDIT Original post had different code here, but I was able to reproduce the problem with the same code.

The alternate version looks like this:

{  
   "Name":"William Shakespeare",
   "Age":51,
   "Birthday":"04/26/1564 00:00:00",
   "<Name>k__BackingField":"William Shakespeare",
   "<Age>k__BackingField":51,
   "<Birthday>k__BackingField":"04/26/1564 00:00:00"
}

Is this a bug? Can I work around it and clean this up? I assume I need to use the Android version in order to run on an Android device, but interestingly, I can reference the MonoAndroid10 version from a Windows console application. Why are there different files for different platforms when .NET is cross-platform?


Solution

  • Is this a bug? Can I work around it and clean this up? I assume I need to use the Android version in order to run on an Android device, but interestingly, I can reference the MonoAndroid10 version from a Windows console application. Why are there different files for different platforms when .NET is cross-platform?

    I've tested the latest AWSSDK.Core (3.3.21.6), this issue persists.

    Then I also tested LitJson separatly with latest version(0.11.0). There is no such issue.

    So the problem appears to be exists only in AWSSDK.Core. Until the framework author fix the issue, the workaround for your problem is to reference LitJson separately and use LitJson.JsonMapper instead of ThirdParty.Json.LitJson.JsonMapper.