Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
I'm able to store my property in CMS database as json string.
public override object SaveData(PropertyDataCollection properties)
{
return "{}";
}
But my dojo widget always gets "null" as value? Where actual serialization/desirialization occurs?
You can register a custom json serializer. This is a simple example:
[ServiceConfiguration(typeof(JsonConverter))]
public class JsonIdentityConverter : JsonConverter
{
private const char _escapeChar = '_';
public override bool CanConvert(Type objectType)
{
return typeof(Identity).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (typeof(string).IsAssignableFrom(reader.ValueType) && typeof(Identity).IsAssignableFrom(objectType))
{
return Identity.Parse(((string)reader.Value).Replace(_escapeChar, ':'));
}
return null;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
Validate.RequiredParameter("writer", writer);
Validate.RequiredParameter("value", value);
writer.WriteValue(value.ToString().Replace(':', _escapeChar));
}
}
I've implemented custom property with custom Type as value (Dictionary).
How can I manage the way my custom value is serialized before passing to dojo editor/and deserialized back from it?