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;
using LeanKit.API.Client.Library.TransferObjects;
public class MyCommentList
public string ReplyText { get; set; }
[JsonProperty(ItemConverterType = typeof(SingleOrArrayConverter<Comment>))]
public List<List<Comment>> ReplyData { get; set; }
public string ReplyCode { get; set; }
namespace LeanKit.API.Client.Library.TransferObjects
public long Id { get; set; }
[Required(ErrorMessage = "Text may not be empty")]
[StringLength(4000, ErrorMessage = "Text may have 2000 symbols only")]
public string Text { get; set; }
public string PostDate { get; set; }
public string PostedByGravatarLink { get; set; }
public long PostedById { get; set; }
public string PostedByFullName { get; set; }
public bool Editable { get; set; }
public int Id { get; set; }
public string Text { get; set; }
public object TaggedUsers { get; set; }
public string PostDate { get; set; }
public string PostedByGravatarLink { get; set; }
public int PostedById { get; set; }
public string PostedByFullName { get; set; }
public bool Editable { get; set; }
class SingleOrArrayConverter<T> : JsonConverter
public override bool CanConvert(Type objectType)
return (objectType == typeof(List<T>));
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
JToken token = JToken.Load(reader);
if (token.Type == JTokenType.Array)
return token.ToObject<List<T>>();
return new List<T> { token.ToObject<T>() };
public override bool CanWrite
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();
public static void Test()
var responseString = GetJson();
var mycomment = JsonConvert.DeserializeObject<MyCommentList>(responseString);
var newJson = JsonConvert.SerializeObject(mycomment, Formatting.Indented);
Console.WriteLine("\nRe-serialized JSON: ");
Console.WriteLine(newJson);
""Text"": ""First comment for this card."",
""PostDate"": ""10/14/2015 at 04:36:02 PM"",
""PostedByGravatarLink"": ""3ab1249be442027903e1180025340b3f"",
""PostedById"": 62984826,
""PostedByFullName"": ""David Neal"",
""ReplyText"": ""Card comments successfully retrieved.""
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");