I’m kinda clueless:
i’ve got this class to send a reply to the server based on a previously given request:
[Route("/system/clientreply")]
public class ClientReply : IReturnVoid
{
public string TmpQueue { get; set; }
public object Object { get; set; }
}
Client replies by putting content in the Object class, for example:
public class Engine
{
public string Id { get; set; }
public string Name { get; set; }
public DateTime? Ts { get; set; }
}
The server knows the type of answers its getting, so it deserialises it back.
Now comes the strange part. When using obj.SerializeAndFormat e.g., i get a neat unixtimems in the Ts field, but when sent to the server, there is NULL parsed. Requestlogs also show NULL.
I highly recommend against using unknown types like object, interfaces or abstract classes in your Services which is a major source of runtime issues where the server has no idea what to deserialize into and will fail to work in some languages which require knowing which type to deserialize into.
The solution is more than likely solved by using Typed DTOs instead of object but if you can provide a stand-alone repro with the HTTP Request / Response Headers sent I can let you know what the issue is.
Fast as always.
Al my DTO’s are typed otherwise. This class is only used for replying to a request send by the server over SSE, to make the client reply some data on which the server explicitly knows whats its asking, and also has and knows the return type. Didn’t think its bad ?
Anyway: i just wanted to post that the issue is solved for me by adding
The object is a hole in your Services contract which can’t be documented by metadata services, requires C# serialization specific hints on the wire (which breaks if Type/Namespaces change), is subject to security restrictions, doesn’t work for primitive/scalar values, fails to work in a number of serializers/formats, etc. So basically I’d avoid using of them whenever possible.
With that said I’ve added support for deserializing arbitrary JSON and JS literals into object properties which deserializes into untyped .NET Data structures as seen in these tests.
Which is enabled by default in ServiceStack Services from v5.0.3 that’s now available on MyGet.
But I’d only recommend using this with 3rd Party API callbacks which passes different JSON data structures to the same endpoint, which you can now use an object property to accept any arbitrary JSON or JS Object literal payload:
[Route("/callback")]
public class Callback : IReturn<CallbackResponse>
{
public object Payload { get; set; }
}
and Payload will be populated into native .NET data structures, e.g. Dictionary<string,object> if payload was a JSON object literal .