public static void WriteJson(this IJsonSerializable obj, JsonTextWriter writer) { writer.WriteStartObject(); var polymorph = obj as IPolymorphable; if (polymorph != null) { writer.WritePropertyName("classId"); writer.WriteValue(polymorph.GetClassId()); // var f = writer.Formatting; // writer.Formatting = Formatting.None; // writer.WritePropertyName("className"); // writer.WriteValue(obj.GetType().Name); // writer.Formatting = f; } obj.WriteJsonFields(writer); writer.WriteEndObject(); }