Extra garbage produced by LitJson serialization with AWS SDK for MonoAndroid10

830 Views Asked by At

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?

2

There are 2 best solutions below

3
On BEST ANSWER

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.

6
On

Your Outpot code is totally different. And it has to deal with Arrays. Faced with that, it has as a two options:

  • Display the result of .ToString() only. In .NET that usually is the class name
  • Do a Dump of the Array contents, in whatever detail level the original programmer intended

Outputting a Array like that is only usefull for Debugging. So make you proper output code already.

As for the Birthday: What is displayed is the Raw Value stored inside DateTIme, not reinterpreted with a System selected Formating. It could be something like "the ticks/seconds since counting started". Honestly I am surprised DateTime can even display that value.