Cannot deserialize DateTime with milliseconds
When trying to fetch an object containing a DateTime with a milliseconds part I get an exception:
System.Runtime.Serialization.SerializationException : There was an error deserializing the object of type MyNamespace.MyClass. String was not recognized as a valid DateTime.
What serializer are you using? The default serializers for XML (XmlSerializer) and JSON (DataContractJsonSerializer) uses serializers from the .NET Framework. If you are sending data as json, I would recommend using PainlessHttp.Serializer.JsonNet that is industry standard.
Hope this helps!
I mostly use this to GET/POST/PUT my .Net objects to a Asp.net Wep API, like:
HttpClient.Post<MyObj>("api/obj", myObjInst);
I just assumed that everything should work out of the box (it mostly does except from the this issue and https://github.com/pardahlman/PainlessHttp/issues/4)
Understood! The idea with the main library is to provide an easy-to-use client without any external dependencies. Unfortunately, that limits the options when it comes to serialization 😄 That is the reason why I made serializaers pluggable so that you could use JsonNet, ServiceStack, Protobuf or any other serialization technology.
There are some information in the README on how to register serializers!
Stumbled upon this once again. I don't manage to get PainlessHttpClient to request Json from my web API. Could you provide sample code on how to do this? I've tried:
var config = new Configuration {
BaseUrl = TestEnvironment.Instance.Url,
Advanced = {
Serializers = new List<IContentSerializer> { PainlessHttp.Serializers.Defaults.DefaultJson.GetSerializer() },
WebrequestModifier = request => request.Headers.Add("Accept", "application/json")
}
};
HttpClient = new HttpClient(config);
However, this gives me errors:
System.AggregateException : One or more errors occurred.
----> System.ArgumentException : The 'Accept' header must be modified using the appropriate property or method.