1

Closed

JsonConverterAttribute not use new IsoDateTimeConverter{Culture = CultureInfo.CreateSpecificCulture("vi")} when call JsonConvert.DeserializeObject. It creates new instance of IsoDateTimeConverter with default culture "en".

description

void Main()
{
   Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en");
   var input = @"{""DateCreated"":""09/08/2013 8:59:23 SA""}";
   JsonConvert.DeserializeObject<TestClass>(input, 
          new IsoDateTimeConverter{Culture = CultureInfo.CreateSpecificCulture("vi")}
          ).Dump();
}
// Define other methods and classes here
public class TestClass
{
   //[JsonConverter(typeof(IsoDateTimeConverter))] // --> If uncomment, Exception thrown
   public DateTime DateCreated {get;set;}
}

file attachments

Closed Oct 3, 2013 at 10:05 AM by JamesNK
You can only use the default settings when using an attribute. Writing a custom contract resolve might solve your issue

comments