servicestackormlite-servicestack

JSON serializer instead of JSV in ServiceStack ORMLite


Despite that JSV promoted as faster and more compact alternative to JSON, it's not supported by many platforms and databases, while JSON is.

How to make ServiceStack ORMLite serialize and de-serialize using JSON format instead of JSV?


Solution

  • Yes OrmLite supports pluggable text serializers which lets you specify different serialization strategies of Complex Types for each available RDBMS provider, e.g:

    Pluggable Text Serializer Examples

    //ServiceStack's JSON and JSV Format
    SqliteDialect.Provider.StringSerializer = new JsvStringSerializer();       
    PostgreSqlDialect.Provider.StringSerializer = new JsonStringSerializer();
    //.NET's XML and JSON DataContract serializers
    SqlServerDialect.Provider.StringSerializer = new DataContractSerializer();
    MySqlDialect.Provider.StringSerializer = new JsonDataContractSerializer();
    //.NET XmlSerializer
    OracleDialect.Provider.StringSerializer = new XmlSerializableSerializer();
    

    You can also provide a custom serialization strategy by implementing IStringSerializer.

    By default all dialects use the existing JsvStringSerializer, except for PostgreSQL which due to its built-in support for JSON, uses the JSON format by default.