Last active
January 21, 2019 21:26
-
-
Save bitbonk/8c949ecc5f1cfd07e40184eb833f6e0f to your computer and use it in GitHub Desktop.
JSON Deserailization .NET Core vs. .NET Classic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$type": "MyNamespace.Dto`6[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], NETClassicApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", | |
"StringProp": "my string", | |
"DoubleProp": 123.0, | |
"FloatProp": 345.0, | |
"ByteArrayProp": { | |
"$type": "System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", | |
"$value": "AQID" | |
}, | |
"UriProp": "http://localhost:80", | |
"DateTimeProp": "2010-09-08T07:06:05.004", | |
"TimeSpanProp": "42.00:00:00" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$type": "MyNamespace.Dto`6[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Double, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Single, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Uri, System.Private.Uri, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.DateTime, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.TimeSpan, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], CoreApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", | |
"StringProp": "my string", | |
"DoubleProp": 123.0, | |
"FloatProp": 345.0, | |
"ByteArrayProp": { | |
"$type": "System.Byte[], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", | |
"$value": "AQID" | |
}, | |
"UriProp": "http://localhost:80", | |
"DateTimeProp": "2010-09-08T07:06:05.004", | |
"TimeSpanProp": "42.00:00:00" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CoreApp | |
{ | |
using System; | |
using MyNamespace; | |
using Newtonsoft.Json; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var result = JsonConvert.SerializeObject( | |
new Dto<string, double, float, Uri, DateTime, TimeSpan> | |
{ | |
StringProp = "my string", | |
DoubleProp = 123.0d, | |
FloatProp = 345.0f, | |
UriProp = new Uri("http://localhost:80"), | |
DateTimeProp = new DateTime(2010,9,8,7,6,5,4), | |
TimeSpanProp = TimeSpan.FromDays(42) | |
}, | |
new JsonSerializerSettings | |
{ | |
TypeNameHandling = TypeNameHandling.All, | |
//TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full, | |
Formatting = Formatting.Indented | |
}); | |
Console.WriteLine(result); | |
} | |
} | |
} | |
namespace MyNamespace | |
{ | |
using System; | |
public class Dto<T1, T2, T3, T4, T5, T6> | |
{ | |
public T1 StringProp { get; set; } | |
public T2 DoubleProp { get; set; } | |
public T3 FloatProp { get; set; } | |
public byte[] ByteArrayProp { get; set; } = { 1, 2, 3 }; | |
public T4 UriProp { get; set; } | |
public T5 DateTimeProp { get; set; } | |
public T6 TimeSpanProp { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment