This project has moved. For the latest updates, please go here.

JsonConverter.ReadJson & How to customize deserialization

May 3, 2010 at 10:06 PM

I started to use Json.NET recently. It is very handy. However, sometime I need to customize how an object is de/serialized from/to Json. 

I know one of the approach is to create my own JsonConverter and implement ReadJson method. My first question is:

Since JsonReader read json sequentially, how does it differentiate between the following cases:

object structure:

Class Point

double X;

double Y;

json 1: {"x": 100, "y": 100}

json 2: {"y":100, "x": 100}

json 1 and json 2 actually represent the same point, but how does JsonReader within the method JsonConverter.ReadJson know which property it is 

reading currently. Then how I could deserialize json in my way? Thanks!


My second question is: 

It seems there are two mechanisms in Json.NET to customize deserialization: 1. using ContractResolver; 2. using JsonConverter

how are they different? which one I should use in what particular situation? are there any other ways to customize de/serialization? 


Thank you!