Can we get a JsonWriter.WriteValue(object) overload?

Aug 11, 2008 at 6:53 AM

I'm hooking up a couple of custom converters to JSON.NET and while it's easy enough to do this in some cases, it's a bit painful if you have a type that contains other types that you're explicitly iterating over. For example, I have a requirement for some legacy code to serialize DataTables and there's no way that I can see to easily get a single JSON value out of the writer of my type is of type object nad I can't call a specific overload of WriteValue.

What I'm currently doing is this:

public override void WriteJson(JsonWriter writer, object dataRow)
{
    JsonSerializer ser = new JsonSerializer();                       
    DataRow row = dataRow as DataRow;

    writer.WriteStartObject();

    foreach (DataColumn column in row.Table.Columns)
    {
        writer.WritePropertyName(column.ColumnName);
        ser.Serialize(writer,row[column]);
    }
    writer.WriteEndObject();
}

which uses the highlevel root Serializer. Seems like there should be a lower level to do this. Is there? So far no luck <g> But certainly writer.WriteValue(object value); would be the expected method to call.

+++ Rick ---

Coordinator
Aug 12, 2008 at 11:12 PM
Done
Aug 13, 2008 at 3:27 AM
Awesome James!