Skip to content

Instantly share code, notes, and snippets.

@joshcough
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshcough/cb780644c86df1e988ee to your computer and use it in GitHub Desktop.
Save joshcough/cb780644c86df1e988ee to your computer and use it in GitHub Desktop.
import scalaz._, Scalaz._
import argonaut._, Argonaut._
/**
* Main prints:
* -\/(Double: [--\(d)])
* \/-(Dubble(56.45))
* \/-(Pint(56))
* \/-(Pint(56))
*/
object ArgonautDoubleWeirdness {
case class Pint(i: Int)
implicit def PintCodecJson: CodecJson[Pint] = casecodec1(Pint.apply, Pint.unapply)("i")
case class Dubble(d: Double)
implicit def DubbleCodecJson: CodecJson[Dubble] = casecodec1(Dubble.apply, Dubble.unapply)("d")
def main (args: Array[String]) {
println(Parse.decodeEither[Dubble]("""{"d":"56.45"}"""))
println(Parse.decodeEither[Dubble]("""{"d":56.45}"""))
println(Parse.decodeEither[Pint]("""{"i":"56"}"""))
println(Parse.decodeEither[Pint]("""{"i":56}"""))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment