Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on JSON deserialiation on migrated questions. #1

Closed
lisardggY opened this issue Feb 26, 2012 · 2 comments
Closed

Error on JSON deserialiation on migrated questions. #1

lisardggY opened this issue Feb 26, 2012 · 2 comments
Assignees

Comments

@lisardggY
Copy link

Hey there.

I'm using BridgeStack to write a script that goes over questions on StackOverflow, and I think I found a bug that causes a crash during JSON deserialization, when the results include a question that was migrated to a different site. Is this a known bug?

This is the exception:

Newtonsoft.Json.JsonSerializationException was unhandled.
Message=Error converting value "main_site" to type >'System.Nullable`1[BridgeStack.SiteTypeEnum]'.
In Json.cs, line 44

(I can get a full stack-trace, if you want).

I define my QuestionQuery like this:

 stackClient.Default.Site = NetworkSiteEnum.StackOverflow;
 var query = new QuestionsQuery
 {
     PageSize = 30,
     Sort = QuerySortEnum.Creation,
     Order = QueryOrderEnum.Descending
 };

and the returned JSON includes this question:
(Note the "main_site" under "other_site" under "migrated to".

{"question_id":9450616,"last_edit_date":1330232950,"creation_date":1330231596,"last_activity_date":1330233221,"locked_date":1330237275,"score":0,"answer_count":0,"migrated_to":{"question_id":394120,"other_site":{"site_type":"main_site","name":"Super User","logo_url":"http://sstatic.net/superuser/img/logo.png","api_site_parameter":"superuser","site_url":"http://superuser.com","audience":"computer enthusiasts and power users","icon_url":"http://sstatic.net/superuser/img/apple-touch-icon.png","site_state":"normal","styling":{"link_color":"#1086A4","tag_foreground_color":"#1087A4","tag_background_color":"#FFFFFF"},"launch_date":1250553600,"favicon_url":"http://sstatic.net/superuser/img/favicon.ico","related_sites":[{"name":"Meta Super User","site_url":"http://meta.superuser.com","relation":"meta","api_site_parameter":"meta.superuser"},{"name":"Chat Stack Exchange","site_url":"http://chat.stackexchange.com","relation":"chat"}],"twitter_account":"StackSuper_User"},"on_date":1330237275},"closed_date":1330237274,"title":"Linux Ram Limits","tags":["linux","bash"],"closed_reason":"off topic","view_count":36,"owner":{"user_id":1233384,"display_name":"Trey G.","reputation":1,"user_type":"registered","profile_image":"http://www.gravatar.com/avatar/45777bf1824d3854753c6e30cce6f405?d=identicon&r=PG","link":"http://stackover flow.com/users/1233384/trey-g"},"link":"http://stackoverflow.com/questions/9450616/linux-ram-limits","is_answered":false}

@ghost ghost assigned bevacqua Feb 26, 2012
@lisardggY
Copy link
Author

Ok, I narrowed it down, cut down the to the exact bit that's crashing. This is the enum from BridgeStack:

public enum SiteTypeEnum
{
    [EnumMember(Value = "main_site")] Main,
    [EnumMember(Value = "meta_site")] Meta
}

And this is the JSON that's being deserialized:

var json = "\"site_type\":\"main_site\"";
var q = JsonConvert.DeserializeObject<SiteTypeEnum?>(json);

Same exception as before:

Newtonsoft.Json.JsonSerializationException: Error converting value "site_type" to type 'System.Nullable1[BridgeStack.SiteTypeEnum]'. ---> System.Exception: Could not cast or convert from System.String to System.Nullable1[BridgeStack.SiteTypeEnum].

bevacqua added a commit that referenced this issue Feb 26, 2012
@lisardggY
Copy link
Author

Awesome. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants