public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Entity entity = value as Entity;
            if (entity == null)
            {
                writer.WriteNull();
                return;
            }

            writer.StartObject();
            writer
                // Write id
                .WithWriter(w =>
                {
                    if (string.IsNullOrWhiteSpace(entity.Id) == false)
                        w.WriteProperty("__id", entity.Id);
                })
                // Write created by
                .WriteProperty("__createdby", entity.CreatedBy)
                // Write properties
                .WithWriter(w =>
                {
                    
                    foreach (var property in entity.Properties)
                        w.WriteProperty(property.Key, property.Value);
                })
                .WithWriter( w => WriteJson(entity, w, serializer) )
                .WithWriter(w =>
                {
                    var attr = entity.Attributes.ToArray();
                    if (attr.Length > 0)
                    {
                        w.WriteProperty("__attributes")
                         .StartObject();
                        // Write attributes
                        for (int i = 0; i < attr.Length; i++)
                            w.WriteProperty(attr[i].Key, attr[i].Value);
                        w.EndObject();
                    }

                })
                .WithWriter(w =>
                {
                    if (entity.Tags.Count() > 0)
                        w.WriteArray("__tags", entity.Tags);
                });
            writer.EndObject();
        }