1

Following the sample here: http://james.newtonking.com/json/help/index.html?topic=html/CustomJsonConverter.htm

I am wondering how JToken.FromObject impacs performance when serialization.

Hoping someone have an asnwer and save me the time of profiling it after doing it.

I have a custom class where I would like to alter the values in the serialization and the sample seems to be a good case to do so. Just wondering if its using extra reflection to do so or JToken.FromObject also is used internally when serializing an object.

1 Answer 1

2

The great thing about OSS is that you can actually see everything yourself:

From the JToken class

internal static JToken FromObjectInternal(object o, JsonSerializer jsonSerializer)
{
     ValidationUtils.ArgumentNotNull(o, "o");
     ValidationUtils.ArgumentNotNull(jsonSerializer, "jsonSerializer");

     JToken token;
     using (JTokenWriter jsonWriter = new JTokenWriter())
     {
         jsonSerializer.Serialize(jsonWriter, o);
         token = jsonWriter.Token;
     }

     return token;
}

There isn't any reflection overhead, just the extra allocation of JTokenWriter which is passed to JsonSerializer.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.