I have an existing SQLite database that is generated in ServiceStack ORMLite. It has a field that represents a property of type Dictionary in C#.
ServiceStack serializes this into the database as JSV which works fine for our current system that runs in all .NET.
I am working on using the existing databases for an Android implementation. Mono is (unfortunately) not an option.
I was wondering if there was a way to force ORMLite to use the JSON serialization for fields outside of actually writing a custom DialectProvider. This would allow me to easily parse the field using available JSON parsers.
Alternatively, a JSV Parser in Java would do the trick as well.
Thanks
The complex Type Serializer used in OrmLite to serialize Complex Types are pluggable:
//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.
There is no Java implementation of the JSV Format as far as I know, but we do have a naive implementation in JavaScript which should provide a good starting point should someone wish to port it to Java.