using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public class SkipDeserializationConverter : JsonConverter
public override bool CanConvert(Type objectType)
throw new NotImplementedException();
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
public override bool CanWrite { get { return false; } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();
public class SupYo : ISupYo
readonly string m_hi = "heya";
public string Hi { get { return m_hi; } }
[JsonProperty(Order = 10)]
public Dictionary<string, object> SomeNestedDataToSkip = new Dictionary<string, object> { { "array", new[] { "a", "b", "c" } }, { "string", "string"}, {"int", 10101} };
public int hiyo { get { return m_hiyo; } }
[JsonConverter(typeof(SkipDeserializationConverter))]
public ISupYo yo { get { return new SupYo(); } }
[JsonProperty(Order = 101)]
public string MoreDataToDeserialize { get; set; }
public static void Test()
sup.MoreDataToDeserialize = "test string";
var json = JsonConvert.SerializeObject(sup);
var mySup = JsonConvert.DeserializeObject<Sup>(json);
Assert.IsTrue(sup.hiyo == mySup.hiyo);
Assert.IsTrue(sup.MoreDataToDeserialize == mySup.MoreDataToDeserialize);
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");