danielcrenna/tweetsharp — Issue #12: json serializer failed to deserialize json to twitter statuses
Author: yoavniran
Created: 2011-12-26 00:53:23+00:00
State: open

Today all of a sudden my app using Tweetsharp stopped receiving new posts from Twitter

When i looked at the logs i could see an exception with a long stack trace running down to the newsoft json objects and a vauge error message about an unexpected Integer token.

After some digging I found that the **TwitterGeoConverter** class was failing to parse the GEO information.
The reason for this is that in almost all of the statuses if there is no GEO location information the 'geo' property is null. in this particular post it wasnt and the coordinates were set to 0,0. (see: https://api.twitter.com/1/statuses/show.json?id=150967582432833536).

This made the serializer think that the values are integers and not floats which meant that the GEO converter in Tweetsharp was not parsing them. Adding the check for the Integer token solved it:

```C#
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}

if (reader.TokenType != JsonToken.StartArray)
{
return null;
}

reader.Read();

var coords = new double[2];

if (reader.TokenType == JsonToken.Float || reader.TokenType == JsonToken.Integer)
{
coords[0] = double.Parse(reader.Value.ToString());
reader.Read();
}
if (reader.TokenType == JsonToken.Float || reader.TokenType == JsonToken.Integer)
{
coords[1] = double.Parse(reader.Value.ToString());
reader.Read();
}

var latitude = coords[0];
var longitude = coords[1];

return new TwitterGeoLocation.GeoCoordinates { Latitude = latitude, Longitude = longitude };
}
```