Skip to content

Argo 3 breaks implicit Number -> Bool conversion #358

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

Closed
jshier opened this issue Apr 6, 2016 · 4 comments · Fixed by #359
Closed

Argo 3 breaks implicit Number -> Bool conversion #358

jshier opened this issue Apr 6, 2016 · 4 comments · Fixed by #359

Comments

@jshier
Copy link
Contributor

jshier commented Apr 6, 2016

With the addition of an actual JSON.Bool case, it seems that the implicit .Number conversion to Bool has been broken. Was this intentional? It's unfortunately common for backend software to return boolean values as 1 or 0. Previously Argo was able to automatically convert these to Bool. Now that's no longer possible. I believe the previous behavior could be returned by adding the previous behavior back to the Bool Decodable extension:

extension Bool: Decodable {
  /**
    Decode `JSON` into `Decoded<Bool>`.

    Succeeds if the value is a boolean, otherwise it returns a type mismatch.

    - parameter j: The `JSON` value to decode

    - returns: A decoded `Bool` value
  */
  public static func decode(j: JSON) -> Decoded<Bool> {
    switch j {
    case let .Bool(n): return pure(n)
    case let .Number(n as Bool): return pure(n)
    default: return .typeMismatch("Bool", actual: j)
    }
  }
}

Would that be an acceptable change?

@gfontenot
Copy link
Collaborator

Ah, crap. Sorry. Yeah, this is inline with the way of handling Int values, so it makes sense to me.

@jshier
Copy link
Contributor Author

jshier commented Apr 6, 2016

Want me to do a PR or is it something you can do quickly?

@gfontenot
Copy link
Collaborator

I'm happy to submit a PR if you'd like.

@gfontenot
Copy link
Collaborator

done

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

Successfully merging a pull request may close this issue.

2 participants