Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Kjetil Mehl
    @aspic
    Hi! I'm trying to provide a client with a more meaningful decode error, and try to traverse the cursorhistory. However, when I manually handle a DecodeResult in a given codec I don't get the history of the parent path, even though I call c.history (it's just empty). Am I overlooking something in the cursor class? :-)
    If I let argonaut handle decodeResult itself (with a simple codec) the history gets appended just fine.
    Andreas Jim-Hartmann
    @devkat
    hi, quick question:
    Parse.decodeOption[Map[String, Seq[String]]](jsonString)
    doesn’t compile since it is missing the implicit EncodeJson for this type
    I tried adding a CodecJson for Seq[A] (based on List), but it didn’t help
    any hints? TIA!
    I’m using version 6.2 BTW
    Colt Frederickson
    @coltfred

    @devkat This in general is a bad place to get help. I've tried a few times and have failed. In this case I think I can help you. If you really wanted to deserialize the Seq version you just need an implicit for "Seq".

    
    scala> implicit def SeqDecodeJson[A](implicit e: DecodeJson[A]): DecodeJson[Seq[A]] = CanBuildFromDecodeJson[A, Seq]
    SeqDecodeJson: [A](implicit e: argonaut.DecodeJson[A])argonaut.DecodeJson[Seq[A]]
    
    scala> Parse.decodeOption[Map[String, Seq[String]]]("""{"foo":["bar","baz"]}""")
    res4: Option[Map[String,Seq[String]]] = Some(Map(foo -> Vector(bar, baz)))

    But remember that if you just deserialize as a Vector or List you can refer to it as a Seq.

    scala> val x: Option[Map[String, Seq[String]]] = Parse.decodeOption[Map[String, Vector[String]]]("""{"key": ["value1", "value2"]}""")
    x: Option[Map[String,Seq[String]]] = Some(Map(key -> Vector(value1, value2)))

    This is because Vector is a Seq.

    Andreas Jim-Hartmann
    @devkat
    @coltfred, thanks a lot for your reply!
    Mark de Jong
    @Fristi
    Is there a variant of xmap on CodecJson where decoding of failure is taken in to account ?
    Mark de Jong
    @Fristi
    This is not nice to write
    implicit val json: CodecJson[MerchantStatus] = codecJson[String]
        .xmap[MerchantStatus](x => fromString(x).getOrElse(sys.error(s"Could not map '$x' to a MerchantStatus")))(_.status)
    Colt Frederickson
    @coltfred
    @Fristi The best thing to do is to write an encode json and decode json instance separately which correctly addresses the partiality of your conversion.
    Mark de Jong
    @Fristi

    This might be a useful contribution:

      implicit class RichCodecJson[A](val codecJson: CodecJson[A]) {
        def narrow[B](f: B => A, g: A => String \/ B): CodecJson[B] =
          CodecJson(
            x => codecJson.encode(f(x)),
            cur =>
              codecJson.decode(cur).flatMap(x => g(x).fold(err => DecodeResult.fail(err, cur.history), DecodeResult.ok))
          )
      }

    Resulting:

    codecJson[String]
        .narrow[MerchantStatus](
          _.status,
          x => fromString(x).fold[String \/ MerchantStatus](-\/(s"Could not map '$x' to MerchantStatus"))(\/-.apply)
        )
    elsehow
    @elsehow
    hey folks
    I'm pretty new to scala and just discovered argonaut, which I love so far
    I have some json that looks like this:
    {
       "events":[
          {
             "type":"trade",
             "tid":1111597035,
             "price":"2559.98",
             "amount":"0.07365713",
             "makerSide":"ask"
          },
          {
             "type":"change",
             "side":"ask",
             "price":"2559.98",
             "remaining":"20.98651537",
             "delta":"-0.07365713",
             "reason":"trade"
          }
       ]
    }
    say that I model both of these as sublcasses of type Event
    is there an idiomatic way to parse this list .as[List[MarketEvent]]?
    Gary Pamparà
    @gpampara
    @elsehow something along the lines of https://gist.github.com/markhibberd/8231912 should help you
    Not sure what you mean with that MarketEventbit, but you can discriminate on the type property to determine which decoder to use
    Yuval Itzchakov
    @YuvalItzchakov
    Hi,
    When migrating from argonaut 6.1 -> 6.2-scalaz, are there any changes in the imports that need to be done accordingly?
    I'm unable to find a decoder for Array[T] all of the sudden.
    Lehel Iszlai
    @iszlai

    Hey guys I have a really basic question,
    for a basic webhook thing I'd like to parse json partially and keep a field as string

       val rawJson: String ="""
    {
      "url": "http://bar",
      "method": "GET",
      "body": "{"tucsfoo":""}",
      "cronExpression": "* * * * *"
    }
    """
    case class CronTask(url: String, method: String, body: String, cronExpression: String)
    
    
    
    object CronTask {
      import argonaut._, Argonaut._
      implicit def PersonCodecJson: CodecJson[CronTask] =
        casecodec4(CronTask.apply, CronTask.unapply)("url", "method", "body", "cronExpression")
    }

    I would love to get back the body as a string, how would i do that?

    Gary Pamparà
    @gpampara
    Doesn't that work?
    Lehel Iszlai
    @iszlai
    @gpampara nope :(
    Kevin Meredith
    @kevinmeredith
    Hello! Will CursorHistory#toString, i.e. on a Left of DecodeResult(result: Either[(String, CursorHistory), A) ever include JSON values? Or it will only include the traversed path, i.e. which keys were walked, and which failed
    u can get a List[CursorOp]
    Pyry-Samuli Lahti
    @Pyppe
    Hi guys! If I have a CodecJson[Example] (defined by casecodec20) but would like to change the decoder so that a particular missing field would default to some value, what would be the way to do it?
    The signature of def flatMapCursor(f: HCursor => DecodeResult[HCursor]): DecodeJson[A] looks promising, but I'm not quite sure if and how could it be utilized.
    Pyry-Samuli Lahti
    @Pyppe
    FYI, solved it by using withFocus:
    implicit def decodeJson = DecodeJson[Example] { c =>
      originalCodec.Decoder.decode(
        c.withFocus(js =>
          if (js.hasField("arrayOfStuff")) js
          else js.withObject(_ + ("arrayOfStuff", jEmptyArray))
        )
      )
    }
    Anirudh Vyas
    @AnirudhVyas
    i have a rather simple problem - I have a case class with name, someXField, paths : Seq[String] -- I try to do casecodec3 using argonaut but argonaut cannot recognize Seq[String] - what am I missing? any suggestions
    Pyry-Samuli Lahti
    @Pyppe
    IIRC there's no implicit codec for Seq. Create one youself, or use e.g. List instead
    Anirudh Vyas
    @AnirudhVyas
    I ended up using List.
    thanks for the help
    Francisco Arámburo
    @FrancoAra
    hello
    why is that this works:
    Json
          .obj()
          .as[Option[String]](DecodeJson[Option[String]] { hcursor =>
            (hcursor --\ "lol").as[Option[String]]
          }) shouldBe DecodeResult.ok(None)
    but this fails:
    Json
          .obj()
          .as[Option[OrderStatus]](DecodeJson[Option[OrderStatus]] { hcursor =>
            (hcursor --\ "lol").as[Option[OrderStatus]]
          }) shouldBe DecodeResult.ok(None)
    with: DecodeResult(Left((Attempt to decode value on failed cursor.,CursorHistory(List(El(CursorOpDownField(lol),false)))))) was not equal to DecodeResult(Right(None)) (OrderJsonSpec.scala:30)
    sidnt
    @sidnt
    So, does "io.argonaut" %% "argonaut" % "6.2.2" at the moment, support automatic codec derivation for an ADT?
    toxicafunk
    @toxicafunk
    pretty much that's what it does
    Pyry-Samuli Lahti
    @Pyppe
    Hmm.. The "argonaut-jawn" % "6.2.2" JAR includes only the manifest? Am I missing something? See e.g. http://central.maven.org/maven2/io/argonaut/argonaut-jawn_2.11/6.2.2/argonaut-jawn_2.11-6.2.2.jar
    Pyry-Samuli Lahti
    @Pyppe
    ^ Created Github issue argonaut-io/argonaut#315
    Raymond Barlow
    @raymanoz
    hey peeps
    how does one deal with ADT encode/decode in argonaut?
    toxicafunk
    @toxicafunk
    Alex Cruise
    @acruise
    Hey folks, I know there's an IDSL for path navigation with history, cursors etc., has anyone built a JsonPath/jq style EDSL for it?
    I've built a prototype with https://github.com/json-path/JsonPath but it's not very scala-like
    Kevin Meredith
    @kevinmeredith

    Hi - is argonaut 6.2.2 backwards compatible with 6.2, i.e. it's truly a "patch" version bump?

    https://github.com/argonaut-io/argonaut/releases/tag/v6.2.2