Custom Property Editor/Value Serialization

Vote:
 

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?

 

#81047
Feb 07, 2014 14:26
Vote:
 

You can't serialize a class that implements IDictionary

#81054
Feb 07, 2014 16:03
Vote:
 

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?

 

#81055
Feb 07, 2014 16:12
Vote:
 

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));
}
}

#81056
Feb 07, 2014 16:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.