Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Sean Parsons
    @seanparsons
    6.2-RC2 is now available.
    Sean Parsons
    @seanparsons
    julien-truffaut: Awesomes!
    Colt Frederickson
    @coltfred
    In argonaut 6.2 how can I go from a type Twhich has anEncodeJsonto a Json. I think .json should work, but it doesn't seem to.
    wedens
    @wedens
    will argonaut support scalajs in 6.2?
    Julien Truffaut
    @julien-truffaut
    @wedens I suppose so it is in master
    wedens
    @wedens
    so, it's there just not published?
    Julien Truffaut
    @julien-truffaut
    yes I don't think it has been published, RC2 is from 19th november but scala.js support landed end of december
    @seanparsons would you mind to release a new version?
    wedens
    @wedens
    how can I get Gen[Json]? it exists in argonaut test sources
    maybe it's worth publishing in separate module?
    shawjef3
    @shawjef3
    @wedens looks like they're not published. :worried:
    I see Argonaut might try to support scalaz and cats separately. Maybe consider using https://github.com/shawjef3/Harmony or picking between scalaz and cats, and then clients can use https://github.com/shawjef3/Harmony to convert?
    I created Harmony specifically to help with the cats/scalaz conflict.
    Jonas Michel
    @jonasrmichel

    In the process of upgrading from 6.1a.x to 6.2-RC2, I'm observing some surprising (to me at least) results upon decoding Options...

    import argonaut._, Argonaut._
    
    case class Foo(a: String)
    implicit val fooDecodeJson: DecodeJson[Foo] = jdecode1L(Foo(_: String))("a")
    
    "{}".decodeEither[Option[Foo]]
    
    // 6.a.x: results in a \/-(None)
    // 6.2-RC2: results in a Left(Attempt to decode value on failed cursor.: CursorHistory(List(El(CursorOpDownField(a),false))))

    Is this intended behavior? If so, how should optional fields be encoded?

    Jonas Michel
    @jonasrmichel
    Aha! I just realized this is actually a byproduct of the fixed re-implementation of DecodeResult.option().
    Jonas Michel
    @jonasrmichel

    Which is good. I'm glad that fix got in. The difference in behavior was just surprising upon upgrade.

    I would encourage those (myself included) who are "cheating" and decoding sum types by pattern matching against tuples of Options to properly decode your sum types with the DecodeJson and DecodeResult ||| combinator.

    Gary Pamparà
    @gpampara
    I’ve never seen that issue, and decoding to option etc just seems strnage to me. DecodeResult is a stucture that can handle failure, so the use of Option as the type of the decode does seem weird to me.
    With that I mean decoding/parseDecoding into Option[Foo]
    Colt Frederickson
    @coltfred
    What's the chance that we can get a new version of 6.2 published? argonaut-io/argonaut#254 isn't in 6.2-RC2
    toxicafunk
    @toxicafunk
    hi, i'm a bit confused about some behaviour on argonaut 6.1
    I have the following worksheet
     package argonaut
    
    import argonaut._
    import argonaut.Argonaut._
    
    import scalaz._
    import Scalaz._
    
    object parser {
        case class Course (
            id: Int
            , teachingCenter_id: Int
            , name: String
            , cycle: String
            , materials: Option[List[String]]
        )
    
        object Course {
          implicit def CourseCodecJson: CodecJson[Course ] =
            Argonaut.casecodec5(Course .apply, Course .unapply)(
                "id"
                  , "teachingCenter_id"
                ,"name"
                ,"cycle"
                ,"materials"
            )
        }
      val res = """[{"id":3,"name":"Math 101","cycle":"First","materials":[],"teachingCenterId":1}]"""
                                                      //> res  : String = [{"id":3,"name":"Math 101","cycle":"First","materials":[],"t
                                                      //| eachingCenterId":1}]
        res.decodeOption[List[Course]]            //> res0: Option[List[argonaut.parser.Course]] = None
        res.parse match {
            case \/-(j) => (+j).\\.flatMap(_.--\("materials")).map( (c:Cursor) => c.focus) == Some(jEmptyArray)
            case -\/(s) => s
        }                                         //> res1: Any = true
    
    }
    "materials":[] produces a None even though its declared as materials: Option[List[String]]
    i would expect this to be valid json
    what am I missing?
    toxicafunk
    @toxicafunk
    oh, its not the parsing, my case class is wrong (teachingCenter_id != teachingCenterId)
    David Ainslie
    @davidainslie
    How would I encode/decode a case class that extends a generic trait e.g.
    trait Blah[A] {
      def blah(a: A): A
    }
    
    case class StringBlah[String]() {
      def blah(a: String) = a.toUpperCase
    }
    Colt Frederickson
    @coltfred
    @davidainslie In general this room is dead, but in your example, blah has nothing to do with serialization...
    David Ainslie
    @davidainslie
    Many thanks for letting me know. I did eventually sort things out. Thanks again
    Colt Frederickson
    @coltfred
    @davidainslie If you have a data type that maps directly to some other type that already has a codec you can use .map, .contramap and .xmap to convert.
    Paul Snively
    @PaulAtBanno
    Hey, everyone! What do I need to import to get the .asJson syntax?
    Or rather, do I need to expose an implicit val in scope if I want that syntax to be available outside a module that does the right import?
    I'd like to have my codecs, imports, etc. in one module, then elsewhere just say myFoo.asJson.
    Gary Pamparà
    @gpampara
    @PaulAtBanno That’s a good question! I’ve never seen that syntax tbh. I just usually use import argonaut._, Argonaut._ and then use .jencode to get the json
    I might be using out of date syntax
    Paul Snively
    @PaulAtBanno
    Hmmm
    Colt Frederickson
    @coltfred
    scala> import argonaut.JsonIdentity._
    import argonaut.JsonIdentity._
    
    scala> "1".asJson
    res0: argonaut.Json = "1"
    @PaulAtBanno JsonIdentity
    If you want to mix that in to another object you're importing you can use object Foo extends argonaut.JsonIdentitys
    Paul Snively
    @PaulAtBanno
    @coltfred: Heya, thanks!
    Colt Frederickson
    @coltfred
    @PaulAtBanno np.
    Paul Snively
    @PaulAtBanno
    OK, more of a dumb implicit/import question: if that same module imports ArgonautShapeless._, how do I expose those implicits outside the module?
    I reallllly want to just say import MyCodecs._ in client code, and have automatic case class codec derivation, etc. "just work."
    Colt Frederickson
    @coltfred
    Sadly, I don't know much about that. If the ArgonautShapeless provides a trait, you could mix that in to MyCodecs?
    SteveDraper
    @SteveDraper

    I assume it's a very deliberate design decision, but I was surprised to discover that Argonaut allows Json numbers to be quoted in the Json (which would technically make them Json strings). For example:

    scala> import argonaut._
    import argonaut._
    
    scala> import Argonaut._
    import Argonaut._
    
    scala> val noQuoteNum = "1"
    noQuoteNum: String = 1
    
    scala> val quotedNum = """"1""""
    quotedNum: String = "1"
    
    scala> noQuoteNum.decodeOption[Int]
    res0: Option[Int] = Some(1)
    
    scala> quotedNum.decodeOption[Int]
    res1: Option[Int] = Some(1)

    Can anyone shed any light on why this behavior was considered desirable for me...?

    Iván Portilla
    @Ivykp
    Hello everybody, i would like to ask you a question. Let's say i have case class Person(id: String, money: Double)i am using Argonaut to allow this entity to be serializable to json. However when i add the codec an evaluate the asJson, i get the money value as scientific notation. Is there any way to avoid this scientific notation?
    SteveDraper
    @SteveDraper
    @Ivykp If its a monetary value then Double is probably the wrong type. Better to normalize it to its minimal unit (cents?) and use an integer type most likely
    Iván Portilla
    @Ivykp
    @SteveDraper thanks for the answer. In my case is was just for example terms, in my real case i need a decimal type.