For those who may be interested in the shell template that I use to implement custom serialization using OrmLite (also works with other ORMs), here is a simple working example with NodaTime types that otherwise would not be serialized correctly: / p>
public class BusinessObject { public class Poco { public readonly BusinessObject BusinessObject; public Poco(BusinessObject businessObject) { this.BusinessObject = businessObject; } public Poco() { this.BusinessObject = new BusinessObject(); } public string Id { get { return this.BusinessObject.Id; } set { this.BusinessObject.Id = value; } } public decimal Amount { get { return this.BusinessObject.Amount; } set { this.BusinessObject.Amount = value; } } public DateTime Dt { get { return this.BusinessObject.Dt.ToDateTime(); } set { this.BusinessObject.Dt = LocalDateTime.FromDateTime(value).Date; } } public string TimeZone { get { return this.BusinessObject.TimeZone.Id; } set { this.BusinessObject.TimeZone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(value); } } public string Description { get { return this.BusinessObject.Description; } set { this.BusinessObject.Description = value; } } } public string Id { get; private set; } public decimal Amount { get; private set; } public LocalDate Dt { get; private set; } public DateTimeZone TimeZone { get; private set; } public string Description { get; private set; } public BusinessObject() { } public BusinessObject(string id, decimal amount, LocalDate dt, DateTimeZone timeZone, string description) { this.Id = id; this.Amount = amount; this.Dt = dt; this.TimeZone = timeZone; this.Description = description; } }
I hope that soon it will be possible to define hooks / callbacks for certain types that should be handled with custom code, as well as the fact that OrmLite will allow you to reconfigure properties with private setters from a constant (currently it will work only in one direction).
Update (2014/03/08) . As a temporary workaround, it is possible that OrmLite uses custom serialization / deserialization by first calling:
JsConfig<BusinessObject>.TreatValueAsRefType = true;
Even if BusinessObject is a reference type. Then you can enjoy the beauty / simplicity / omnipresence:
JsConfig<BusinessObject>.RawSerializeFn = bo => bo.Serialize(); JsConfig<BusinessObject>.RawDeserializeFn = str => BusinessObject.Deserialize(str);
We hope that support for user matching will be added soon (so, for example, NodaTime.LocalDate can be matched with DateTime instead of a string).
Erwin mayer
source share