Skip to content

Serialization deserialization

Arxisos edited this page Feb 28, 2012 · 5 revisions

Serialization and deserialization

ServiceStack serializes and deserializes your DTOs automatically. If you want to override the default serializers or you want to add a new format, you have to register your own Content-Type:

string contentType = "application/yourformat"; //To override JSON eg, write "application/json"
var serialize = (IRequestContext requestContext, object response, Stream stream) => ...;
var deserialize = (Type type, Stream stream) => ...;

//In AppHost Configure method
//Pass two delegates for serialization and deserialization
this.ContentTypeFilters.Register(contentType, serialize, deserialize);	

To skip the serialization of the request DTO, you can add the IRequiresRequestStream interface to directly retrieve the stream without populating the request DTO.

//Request DTO
public class Hello : IRequiresRequestStream
{
    /// <summary>
    /// The raw Http Request Input Stream
    /// </summary>
    Stream RequestStream { get; set; }
}

Clone this wiki locally