/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to. /// </param><param name="value">The value.</param><param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { var viewModel = _viewModelMapper.ToDictionary(value as BaseViewModel); writer.WriteStartObject(); foreach (var property in viewModel) { writer.WritePropertyName(property.Key, true); serializer.Serialize(writer, property.Value); } writer.WriteEndObject(); } }