Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:39
    scala-steward closed #1866
  • 13:39
    scala-steward commented #1866
  • 13:39
    scala-steward review_requested #1872
  • 13:39
    scala-steward opened #1872
  • Dec 02 23:18
    Slakah commented #1074
  • Dec 02 21:58
    gatear commented #1074
  • Dec 02 05:32
    scala-steward closed #1870
  • Dec 02 05:32
    scala-steward commented #1870
  • Dec 02 05:32
    scala-steward review_requested #1871
  • Dec 02 05:32
    scala-steward opened #1871
  • Dec 01 23:37
    scala-steward review_requested #1870
  • Dec 01 23:37
    scala-steward opened #1870
  • Nov 30 21:50
    zmccoy closed #1836
  • Nov 30 17:23
    zmccoy commented #1692
  • Nov 30 15:41
    codecov-commenter commented #1869
  • Nov 30 15:39
    codecov-commenter commented #1869
  • Nov 30 15:23
    scala-steward review_requested #1869
  • Nov 30 15:23
    scala-steward opened #1869
  • Nov 30 14:47

    zarthross on main

    Fix the broken link for generic… Merge pull request #1867 from S… (compare)

  • Nov 30 14:47
    zarthross closed #1867
Fabrice Sznajderman
@fabszn_gitlab
Many thanks for your help.
Fabrice Sznajderman
@fabszn_gitlab
I found what I am did wrong :)
Tharindu Galappaththi
@TharinduDG

When I'm trying to start a spark-shell(spark 3.0.1) with a custom jar I'm getting this error

java.lang.NoSuchMethodError: 'shapeless.DefaultSymbolicLabelling shapeless.DefaultSymbolicLabelling$.instance(shapeless.HList)'
  at com.cognite.sdk.scala.v1.GenericClient$anon$lazy$macro$5$1.inst$macro$1$lzycompute(Client.scala:202)
  at com.cognite.sdk.scala.v1.GenericClient$anon$lazy$macro$5$1.inst$macro$1(Client.scala:202)
  at com.cognite.sdk.scala.v1.GenericClient$.<init>(Client.scala:202)
  at com.cognite.sdk.scala.v1.GenericClient$.<clinit>(Client.scala)
  at cognite.spark.v1.DefaultSource$.$anonfun$getProjectFromAuth$1(DefaultSource.scala:393)
  at cats.effect.internals.IORunLoop$.step(IORunLoop.scala:302)
  at cats.effect.IO.unsafeRunTimed(IO.scala:338)
  at cats.effect.IO.unsafeRunSync(IO.scala:256)
  at cognite.spark.v1.DefaultSource$.getProjectFromAuth(DefaultSource.scala:396)
  at cognite.spark.v1.DefaultSource$.$anonfun$parseRelationConfig$4(DefaultSource.scala:315)
  at scala.collection.MapLike.getOrElse(MapLike.scala:131)
  at scala.collection.MapLike.getOrElse$(MapLike.scala:129)
  at org.apache.spark.sql.catalyst.util.CaseInsensitiveMap.getOrElse(CaseInsensitiveMap.scala:30)
  at cognite.spark.v1.DefaultSource$.parseRelationConfig(DefaultSource.scala:315)
  at cognite.spark.v1.DefaultSource.createRelation(DefaultSource.scala:89)
  at cognite.spark.v1.DefaultSource.createRelation(DefaultSource.scala:62)
  at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:344)
  at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:297)
  at org.apache.spark.sql.DataFrameReader.$anonfun$load$2(DataFrameReader.scala:286)
  at scala.Option.getOrElse(Option.scala:189)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:286)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:221)

I'm using circe 0.14.1 which seems to use shapeless 2.3.6.

I would appreciate any help to resolve this issue
Imran Sarwar
@imranbutt-java

Is there any raw json encoder decoder, in circe ?
I have created from json schema anyEncoder[Any] that has all the cases, but even converting json to Map[String, Any], I get the error

scala.MatchError: "㈃ἅ" (of class io.circe.Json$JString)

with this encoder

def anyEncoder: Encoder[Any] = Encoder.instance(((a: Any) => a match {
      case null => Json.Null
      case (b @ ((_): Boolean)) => b.asJson
      case (b @ ((_): Byte)) => b.asJson
      case (s @ ((_): Short)) => s.asJson
      case (i @ ((_): Int)) => i.asJson
      case (l @ ((_): Long)) => l.asJson
      case (f @ ((_): Float)) => f.asJson
      case (d @ ((_): Double)) => d.asJson
      case (s @ ((_): String)) => s.asJson
      case (u @ ((_): java.util.UUID)) => u.asJson
      case (a @ ((_): Array[Boolean] @unchecked)) => a.asJson
      case (a @ ((_): Array[Byte] @unchecked)) => a.asJson
      case (a @ ((_): Array[Short] @unchecked)) => a.asJson
      case (a @ ((_): Array[Int] @unchecked)) => a.asJson
      case (a @ ((_): Array[Long] @unchecked)) => a.asJson
      case (a @ ((_): Array[Float] @unchecked)) => a.asJson
      case (a @ ((_): Array[Double] @unchecked)) => a.asJson
      case (s @ ((_): Array[Any] @unchecked)) => s.toList.asJson(Encoder.encodeList(anyEncoder))
      case (s @ ((_): Seq[Any] @unchecked)) => s.asJson(Encoder.encodeSeq(anyEncoder))
      case (ma @ ((_): Map[String, Any] @unchecked)) => ma.asJson(Encoder.encodeMapLike(KeyEncoder.encodeKeyString, anyEncoder, ((x$1) => x$1.toSeq)))
    }))
Felix Bjært Hargreaves
@hejfelix
is it possible to configure derived codecs in Scala 3 ?
Artie Pesh-Imam
@apeshimam
Can someone help me figure out what Imd oing wrong here
      import io.circe.generic.semiauto._, io.circe.syntax._, io.circe.parser._
      val decoderLocalBillLineItem: Decoder[LocalBillLineItem] = deriveDecoder
      val decoderLocalBill: Decoder[LocalBill] = deriveDecoder

      case class LocalBillLineItem(description: String, unitAmount: Double, quantity: Int, discountAmount: Int,
                                   discoutPercentage: String, subtotal:Int, taxAmount: Int, totalAmount: Double,
                                   accountId: Int, taxRateId: String, itemId: String, classId: String, locationId: String)

      class LocalBill(billUuid: String, reference: String, issueDate: String, dueDate: String, codatModifiedAt: String,
                      sourceModifiedAt: String, currency: String, supplierUuid: Int, billStatus: String, subtotal: Double,
                      taxAmount: Int, totalAmount: Double, amountDue: Double, lineItems: Seq[LocalBillLineItem],
                      note: String, invoiceUuid: String, syncStatus: String, lastSyncedAt: String, externalBillId: String,
                      internalModifiedAt: String, deletedAt: String)


      val bill = """{
                   |  "bill_uuid": "3cf7e07e-a9da-4cfa-bd97-f54c2cd0f6d5",
                   |  "reference": "INV3018",
                   |  "issue_date": "2021-10-31T12:00:00Z",
                   |  "due_date": "2021-11-30T12:00:00Z",
                   |  "codat_modified_at": "",
                   |  "source_modified_at": "",
                   |  "currency": "USD",
                   |  "currency_rate": "",
                   |  "supplier_uuid": 1378,
                   |  "bill_status": "OPEN",
                   |  "subtotal": 187774.79,
                   |  "tax_amount": 0,
                   |  "total_amount": 187774.79,
                   |  "amount_due": 187774.79,
                   |  "line_items": [
                   |    {
                   |      "description": "Invoice INV3018",
                   |      "unit_amount": 187774.79,
                   |      "quantity": 1,
                   |      "discount_amount": 0,
                   |      "discount_percentage": "",
                   |      "subtotal": 0,
                   |      "tax_amount": 0,
                   |      "total_amount": 187774.79,
                   |      "account_id": 109,
                   |      "tax_rate_id": "NON",
                   |      "item_id": "",
                   |      "class_id": "CLASS_4200000000000236781",
                   |      "location_id": ""
                   |    }
                   |  ],
                   |  "note": "INV3018",
                   |  "invoice_uuid": "3cf7e07e-a9da-4cfa-bd97-f54c2cd0f6d5",
                   |  "ledger_uuid": "451c69dd-4cbf-4825-8591-1c75f713568f",
                   |  "sync_status": "UNSYNCED",
                   |  "last_synced_at": "",
                   |  "external_bill_id": "",
                   |  "internal_modified_at": "2021-11-05T04:58:09.147Z",
                   |  "deleted_at": ""
                   |}""".stripMargin
        val r = decode[LocalBill](bill)
        r.isRight shouldBe true÷
this is super simple. I dont have any exocit types
exotic
could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[LocalBill]
val decoderLocalBill: Decoder[LocalBill] = deriveDecoder
lambook
@lambook

Hello,

Can someone tell me why this code is not compiling ? and how can correct, thnx


  import io.circe.parser.decode
  import io.circe.syntax.*
  import io.circe.Decoder
  import io.circe.Encoder
  import io.circe.generic.semiauto.deriveEncoder
  import io.circe.generic.semiauto.deriveDecoder

  final case class Hello[T](
                             source: String,
                             version: Int = 1,
                             data: List[T]
                           )

  object Hello {
    implicit def helloEncoder[T: Encoder]: Encoder[Hello[T]] = deriveEncoder
    implicit def helloDecoder[T: Decoder]: Decoder[Hello[T]] = deriveDecoder
  }


  def decodeGeneric[T] (json String): Hello[T] ={

      decode[Hello[T]](json)
  }
no implicit argument of type io.circe.Decoder[com.sample.TestCirce.Hello[T]] was found for an implicit parameter of method decode in trait Parser.
I found:

    com.sample.TestCirce.Hello.helloDecoder[T](
      io.circe.Decoder.importedDecoder[T](
        /* missing */summon[io.circe.export.Exported[io.circe.Decoder[T]]]
      )
    )

But no implicit values were found that match type io.circe.export.Exported[io.circe.Decoder[T]].
    decode[Hello[T]](json)
ollijh
@liff:matrix.org
[m]
@lambook: you need to have a Decoder constraint in decodeGeneric as well, i.e. def decodeGeneric[T: Decoder](json: String): Hello[T] = …
lambook
@lambook
@liff:matrix.org Thnx
def decodeGeneric[T: Decoder] (json : String): Hello[T] ={ decode[Hello[T]](json)}
How can i return Hello[T]
it says
Found: Either[io.circe.Error, com.sample.TestCirce.Hello[T]] Required: com.sample.TestCirce.Hello[T]
ollijh
@liff:matrix.org
[m]
you need to handle the possible error somehow
i missed it there but decode returns an Either with an error in Left if the parsing or decoding failed
lambook
@lambook

@liff:matrix.org Thnx , i have changed the code to this


  case class Peer(addess: String,node_id: String)

  final case class Hello[T](id: Long,version: String , data: Option[T] )

  object Hello {
    implicit def helloEncoder[T: Encoder]: Encoder[Hello[T]] = deriveEncoder
    implicit def helloDecoder[T: Decoder]: Decoder[Hello[T]] = deriveDecoder

  }

   def toJson[T:  Encoder](t : T) : String ={
     val json : io.circe.Json = t.asJson
     json.toString
   }

  def fromJson[A: Decoder](jsonStr: String):Hello[A] =
    decode[Hello[A]](jsonStr) match {
      case Right(result) => result
      case Left(error) => throw error
    }

  val p = Peer("dfdrgdrg","drgdfgdftg")
  val r1 = new Hello(1,  "32", Some(p))

  toJson[Hello[Peer]](r1)

!! But the last line does not compile and i have this error :

and i have tried with toJsonHello and get the same error

no implicit argument of type io.circe.Encoder[com.sample.TestCirce.Hello[com.sample.TestCirce.Peer]] was found for an implicit parameter of method toJson in object TestCirce.
I found:

    io.circe.Encoder.encodeIterable[com.sample.TestCirce.Peer, 
      com.sample.TestCirce.Hello
    ](
      io.circe.Encoder.AsRoot.importedAsRootEncoder[com.sample.TestCirce.Peer](
        /* missing */
          summon[
            io.circe.export.Exported[
              io.circe.Encoder.AsRoot[com.sample.TestCirce.Peer]
            ]
          ]
      )
    , ???)

But no implicit values were found that match type io.circe.export.Exported[io.circe.Encoder.AsRoot[com.sample.TestCirce.Peer]].
  toJson[Hello[Peer]](r1)

any idea

Thnx

lambook
@lambook
Hi
I have this error
cannot reduce summonFrom with
 patterns :  case given decodeA @ _:io.circe.Decoder[Seq[Any]]
             case given evidence$2 @ _:deriving.Mirror.Of[Seq[Any]]
What do this mean plz?
lambook
@lambook
i had this after adding Seq[Any] to my class :
final case class Hello[T](id: Long,version: String , data: Option[T] , other : Seq[Any])
What s the problem here?
ollijh
@liff:matrix.org
[m]
in the first case, you need to declare an Encoder and Decoder for Peer, like you have for Hello
for Any there is no Encoder or Decoder
relevant: circe/circe#216
lambook
@lambook
Thnx, i m usine Map[String,Any] as parameters fot a requested and i need to deserialize it from json
lambook
@lambook
any way in circ to ser/deser Map[String,Any]?
lambook
@lambook
odenzo
@odenzo
Try again: Trying to write a simple codec in Scala 3 with Circe. using : summon[Codec[Int]] gives me a null.
I guess because I don't have a 'given' clause. So,
def makeCodec(using c:Codec[Int])= {
c.iemap(v=> ieValidate(v))((g:UInt8)=> g.toInt)
}
works. but val c = summon[Codec[Int]] ; c.iemap(....) doesn't.
Just getting up to speed with Scala 3 , using "import io.circe.{given,*}
Wondering if anybody has pointers to Scala 3 Circe examples?
My minigoal is given myCodec:CodecUInt8 = { c.iemap(fn1, fn2) } but I can't get the syntax correct :-(
heksesang
@heksenlied:matrix.org
[m]
summon[Codec[Int]] cannot give you null - such a statement should either not compile or provide you with the object you asked for.
Also, there exists no Codec[Int] definition, I believe. There does exist Decoder[Int] and Encoder[Int].
odenzo
@odenzo
Sorry, you are correct, regarding summon. I am getting different results each compile. But, yeah, my underlying issue was actually no Decoder[Int] it seems?
8 replies
heksesang
@heksenlied:matrix.org
[m]
The problem is that there is no Codec[Int]. A Codec is simply a combination of Decoder and Encoder. Since both of the latter exist for Int, you could simply construct a given Codec[Int] = ... yourself.
None of the basic types have a Codec defined.
Generally, you should write your using-clauses with using Decoder[A], Encoder[A] instead of using Codec[A].
Because Codec is not really treated as a first-class citizen in circe as it is now.
I don't think there ever has been anything like that. Mean to recall I have had to make it myself for every project where I have wanted something like that.
odenzo
@odenzo
(Ok - I replied in thread, but thank you for the reply and my understanding is a bit better now).
heksesang
@heksenlied:matrix.org
[m]
The first given is that "magic" that makes you get a Codec as long as there exists an Encoder and Decoder in scope.
odenzo
@odenzo
Oh, that is excellent!
Got it all working, many thanks
Emerson Coskey
@EmersonCoskey
I'm having some issues using circe in my scala.js project with scalajs-bundler. I know this is relatively off topic, but the bundler works fine except in this one case. At first, the problems were because I was dumb and used %% instead of %%% in build.sbt, but now that that's fixed scalajs-bundler outputs a ton of "warnings" that result in the project not functioning. They're mostly from the node module source-map-loader, which says it can't find a bunch of source files from Shapeless. Is this a common issue? What can I do to fix it?
[warn] (Emitted value instead of an instance of Error) Cannot find source file '../../../../../../../../runner/work/shapeless/shapeless/core/src/main/scala/shapeless/generic.scala': Error: Can't resolve '../../../../../../../../runner/work/shapeless/shapeless/core/src/main/scala/shapeless/generic.scala' in '/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main'
[warn] NonErrorEmittedError: (Emitted value instead of an instance of Error) Cannot find source file '../../../../../../../../runner/work/shapeless/shapeless/core/src/main/scala/shapeless/generic.scala': Error: Can't resolve '../../../../../../../../runner/work/shapeless/shapeless/core/src/main/scala/shapeless/generic.scala' in '/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main'
[warn]     at emitWarning (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/webpack/lib/NormalModule.js:154:16)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/source-map-loader/index.js:74:7
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:213:14
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:285:5
[warn]     at eval (eval at create (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:285:5
[warn]     at eval (eval at create (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:285:5
[warn]     at eval (eval at create (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:285:5
[warn]     at eval (eval at create (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:285:5
[warn]     at eval (eval at create (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enhanced-resolve/lib/Resolver.js:285:5
[warn]     at eval (eval at create (/home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
[warn]     at /home/emerson/Projects/Scala/BSVis/target/scala-2.13/scalajs-bundler/main/node_modules/enha
King HO
@KingHO2359

Hi everyone, I'm using circe - Scala. I need to implement the encoders/decoders with ADTs. However, I am stumped by a specific case where, like that:

sealed trait Event1
case class Foo1(i: Int) extends Event1
case class Bar1(s: String) extends Event1

sealed trait Event2
case class Foo2(list_foo1: List[Event1]) extends Event2

I use the "A more generic solution" in https://circe.github.io/circe/codecs/adt.html

And then:

(Foo2(List(Foo1(1000),Foo1(2000),Bar1("string"))): Event2).asJson.noSpaces
// {"list_foo1":[{"Foo1":{"i":1000}},{"Foo1":{"i":2000}},{"Bar1":{"s":"string"}}]}

It will be exist "Foo1", "Bar1" in the json.
That is not my expectation.
Please give me some ideas with many thanks.

Antoine Doeraene
@sherpal
what would you expect to get, them?
(or rather, what do you want to get ? :) )