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

How to deserialize into enums without failing with 'unknown variant'? #470

Closed
nicokosi opened this issue Aug 3, 2018 · 1 comment
Closed

Comments

@nicokosi
Copy link

nicokosi commented Aug 3, 2018

I currently use serde_json for a side project in order to parse GitHub events API's output.

The GitHub events API returns many event types, such as:

CheckRunEvent
CheckSuiteEvent
CommitCommentEvent

etc.

I am trying to use serde_json::from_str to parse events for a subset of event types:

#[derive(Debug, Deserialize, Eq, PartialEq)]
pub enum Type {
    IssueCommentEvent,
    PullRequestEvent,
    PullRequestReviewCommentEvent,
}

It currently fails because of an unknown variant.

Is there a way to skip content with "unknown enums"? In my case, I would like to only deserialize RawEvent structures with a type that is present in the Type enumeration.

PS: I had a look to the documentation / GitHub issues but I could not figure it out. 😇

@nicokosi nicokosi changed the title How to deserialize to enums without failing? How to deserialize into enums without failing with unknown variant? Aug 3, 2018
@nicokosi nicokosi changed the title How to deserialize into enums without failing with unknown variant? How to deserialize into enums without failing with 'unknown variant'? Aug 3, 2018
@nicokosi
Copy link
Author

nicokosi commented Aug 4, 2018

It duplicates issues #342 and serde-rs/serde#912. Closing this issue.

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

No branches or pull requests

2 participants