Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Alex Cruise
    @acruise
    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

    Nevermind, I see:

    All minor releases (from 6.0 onwards) are binary compatible, i.e. 6.1.x stream are drop in replacements, and the same will be true for 6.2.x, but going from 6.1 to 6.2 may require changes or recompilation.

    on http://argonaut.io/

    Eric K Richardson
    @ekrich
    Hi Guys, trying to convert some test code from lift-json to argonaut so I can take advantage of Scala Native support and 2.13 support. The is the code I'm trying to convert. https://github.com/ekrich/sconfig/blob/master/sconfig/src/test/scala/org/ekrich/config/impl/JsonTest.scala#L60-L92
    The toJson I'm having more luck with. I'm have difficulty with JNumber pattern matching. I have somelike this.
     private[this] def fromJson(json: Json): AbstractConfigValue = {
        import scala.collection.JavaConverters._
    
        json match {
          case JObject(fields) =>
            val m = new HashMap[String, AbstractConfigValue]()
            fields.toMap.foreach({ field =>
              m.put(field._1, fromJson(field._2))
            })
            new SimpleConfigObject(fakeOrigin(), m)
          case JArray(values) =>
            new SimpleConfigList(fakeOrigin(), values.map(fromJson(_)).asJava)
          case JNumber(i) =>
            i match {
              case JsonLong(v) => longValue(v)
              case JNumber(v) => i.
            }
    Also, having some difficulty with matching jNull and or friends.
    Any help appreciated.
    Rohde Fischer
    @rohdef
    is it correctly observed that I cannot parse a String to Json and get some strongly typed error?
    Rohde Fischer
    @rohdef
    I guess the Scaladoc answers that, since I cannot find any error types :)
    D Cameron Mauch
    @DCameronMauch
    I have an ADT called Product (sealed trait with a few case objects). I created encoder and decoder for it. But I need to encode/decode for Option[Product]. How do I do that?
    I would have thought if the base type has an encoder/decoder, it would already know how to handle an Option of that type.
    D Cameron Mauch
    @DCameronMauch
    Ah, my bad. Apparently, my ADT name had a conflict. It thought I was referring to Scala.Product, and not my ADT. Added import, and it works now.
    D Cameron Mauch
    @DCameronMauch
    Does anyone know how to create an encoder for a map? My specific type is Map[String, List[ZonedDateTime]].
    Andriy Plokhotnyuk
    @plokhotnyuk
    @DCameronMauch try jsoniter-scala, it already has much safe and efficient support of any Scala collections and ISO-8601 representation for java.time._ types: implicit val codec: JsonValueCodec[Map[String, List[ZonedDateTime]]] = JsonCodecMaker.make(CodecMakerConfig())
    D Cameron Mauch
    @DCameronMauch
    That doesn’t appear to work with Argonaut. I have no choice but to use Argonaut at this time.
    Andriy Plokhotnyuk
    @plokhotnyuk
    @DCameronMauch you always have choices, just not skip them... btw, I'm not sure that library maintainers care about users: argonaut-io/argonaut#314
    D Cameron Mauch
    @DCameronMauch
    I have to work within the parameters that I am given by the people who employee me. For today, that means I have to use Argonaut. So my only choices involve getting another job or endangering this one.
    Andriy Plokhotnyuk
    @plokhotnyuk
    @DCameronMauch Are their services opened to the wild wide world? Could you please share URL of some their endpoint? I will help you to show them what can happen... ;)
    D Cameron Mauch
    @DCameronMauch
    Just looking for a solution - not to rock the boat
    Rocking the boat and having that be interpreted as a positive and constructive thing is not currently in my skill set
    toxicafunk
    @toxicafunk
    A JSON is a basically a Map already
    D Cameron Mauch
    @DCameronMauch
    @toxicafunk thanks!
    Mohamedali10
    @Mohamedali10

    Hi, I have the following string that I pass to a Parse.EncodeEither method like below:

      val test ="""{"key":{"serial":0},"checkIn":true,"repositoryID":"rep_id","state":"disabled"} """
        val re = Parse.decodeEither[A](test).left.map(MalformedContent(_))

    I'am using argonaut 6.2.2, this code result in the below error:

    Left(MalformedContent(String: CursorHistory(List(El(CursorOpDownField(serial),true), El(CursorOpDownField(key),true))),None))
    Mohamedali10
    @Mohamedali10
    could the problem because of the tyoe of the serial number
    toxicafunk
    @toxicafunk
    That A looks suspicious
    Mohamedali10
    @Mohamedali10
    i will try to remove it
    even if I removed the A I have the same issue
    toxicafunk
    @toxicafunk
    Try something like parse(txt) match { case Right(j) => j case Left(failure) => Json.fromString(s"$failure") }
    I think for decodeEither[A] you would need sine case class that describes your Json
    That case class would be your A
    Without a case class for your codec you can only parse to a generic Json
    Mohamedali10
    @Mohamedali10
    parsing works correctly but the problem is with the decoding
    toxicafunk
    @toxicafunk
    So where's your case class and your decoder?
    Mohamedali10
    @Mohamedali10
    Hi is it possible to define Read play-json object from its argonaut decoding?
    Mohamedali10
    @Mohamedali10

    Hello, I have the following trait and case classes:

    sealed trait Base
     sealed trait  First extends Base
    case class Second(s: String) extends First

    Can someone tell me please How to define a codec json for the Base type?

    Casper Thule
    @CThuleHansen

    In project A i have

    sealed trait ParameterValue
    Case Class IntegerVal(v: int) extends ParameterValue

    and in project B i have a companion object to ParameterValue

    Object ParameterValue {
      implicit val dec: DecodeJson[ParameterValue] = DecodeJson(c =>
        c.as[Int].map[ParameterValue](IntegerVal(_)))
    }

    and also in project b:

    Object MMC
    {
      implicit val dec: DecodeJson[MMC] = DecodeJson(r => for {
        parameters <- (r --\ "parameters").as[Map[String, ParameterValue]]
      } yield MMC(parameters));
    }

    yet it fails that it cannot find the decoder for ParameterValue.

    Is it an issue to have the companion object in another project than the trait and case classes?
    Any ideas?

    Andriy Plokhotnyuk
    @plokhotnyuk
    @CThuleHansen AFAIK a companion object can be defined in the same source file only
    Casper Thule
    @CThuleHansen

    @plokhotnyuk is there another way to achieve my goal of having the data in one project and the conversion in another? I do not mind it to be more explicit. But I if I try to do

    parameters <- (r --\ "parameters").as[Map[String, ParameterValue]](ParameterValue.dec)

    then I get that it needs to the type to be DecodeJson[Map[String, ParameterValue]] but has the type DecodeJson[ParameterValue] which indicates, that I need to combine a map decoder with a parametervalue decoder. I have found the operation &&& to do this, but i cannot find the map decoder in argonaut

    Casper Thule
    @CThuleHansen

    Okay solved it by:

    Object MMC
    {
      implicit val dec: DecodeJson[ParameterValue] = DecodeJson(c =>
        c.as[Int].map[ParameterValue](IntegerVal(_)))
      implicit val dec: DecodeJson[MMC] = DecodeJson(r => for {
        parameters <- (r --\ "parameters").as[Map[String, ParameterValue]]
      } yield MMC(parameters));
    }

    yet I would still love to know how to combine an implicit with an explicit decoder

    Casper Thule
    @CThuleHansen
    Ah found it: parameters <- (r --\ "parameters").as[Map[String, ParameterValue]](argonaut.DecodeJson.MapDecodeJson(ParameterValueDecDecoder.parameterValueDec))
    Andriy Plokhotnyuk
    @plokhotnyuk
    Beware that Scala's default Map introduces vulnerabilities: scala/bug#11203
    Moreover, the Argonaut library suffers from it: argonaut-io/argonaut#314
    Casper Thule
    @CThuleHansen
    hmm yes that is not good
    Thank you for bringing it to my attention @plokhotnyuk
    Alissa Pajer
    @alissapajer

    is the intent for OptionDecodeJson to decode to Some when the value decodes successfully and fail to decode when the value does not decode successfully?

    scala> Json.jNumber(42).as(OptionDecodeJson(JBooleanDecodeJson))
    res29: argonaut.DecodeResult[slamdata.Predef.Option[Boolean]] = DecodeResult(Left((java.lang.Boolean,CursorHistory(List()))))

    it behaves this way because DecodeResult#option behaves this way. DecodeResult#option is used in the implementation for OptionDecodeJson here: https://github.com/argonaut-io/argonaut/blob/v6.3.0/argonaut/shared/src/main/scala/argonaut/DecodeJson.scala#L345

    Alissa Pajer
    @alissapajer
    scala> (Json.obj(("bar", Json.jNumber(42))).hcursor --\ "foo").as[Option[String]]
    res37: argonaut.DecodeResult[slamdata.Predef.Option[slamdata.Predef.String]] = DecodeResult(Right(None))
    
    scala> (Json.obj(("foo", Json.jNumber(42))).hcursor --\ "foo").as[Option[String]]
    res39: argonaut.DecodeResult[slamdata.Predef.Option[slamdata.Predef.String]] = DecodeResult(Left((String,CursorHistory(List(El(CursorOpDownField(foo),true))))))
    I would expect the later to return DecodeResult(Right(None)) as well. If I want to ensure that the decoder doesn't fail in the latter case, I can simply check the result, and return Right(None) if it failed. I just hadn't realized it had this behavior til now :)
    Alissa Pajer
    @alissapajer
    This definition of the Option decoder makes it so the JSON will decode when the locus is omitted, meaning that you can have optional values in your JSON format specification