by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 29 20:25
    scala-steward review_requested #1543
  • Sep 29 20:25
    scala-steward opened #1543
  • Sep 29 17:14
    Lasering edited #1542
  • Sep 29 17:10
    Lasering opened #1542
  • Sep 28 12:27
    codecov-commenter commented #1541
  • Sep 28 12:24
    codecov-commenter commented #1541
  • Sep 28 12:12
    scala-steward review_requested #1541
  • Sep 28 12:12
    scala-steward opened #1541
  • Sep 24 09:59
    travisbrown closed #1533
  • Sep 24 09:57
    travisbrown closed #1535
  • Sep 24 09:56

    travisbrown on master

    Update refined, refined-scalach… (compare)

  • Sep 24 09:56
    travisbrown closed #1539
  • Sep 21 14:33
    neko-kai opened #1540
  • Sep 20 10:33
    codecov-commenter commented #1539
  • Sep 20 10:30
    codecov-commenter commented #1539
  • Sep 20 10:18
    scala-steward review_requested #1539
  • Sep 20 10:18
    scala-steward opened #1539
  • Sep 18 16:34
    scala-steward opened #1538
  • Sep 18 16:34
    scala-steward review_requested #1538
  • Sep 16 21:28
    benhutchison commented #877
xmoooz
@xmoooz
@travisbrown would you explain more or give me a link. thanks
Tushar Mathur
@tusharmath
Hi, when should I use semi auto vs auto? I am always confused.
Paul Roman
@romusz

Hi, Has anybody got codec derivation working with Dotty. I tried Circe 0.13.0 with Dotty 0.22.0-RC1 as per info in the release notes - tried the example, didn't get far:

scala> import io.circe.Codec
     | 
     | sealed trait Event derives Codec.AsObject
3 |sealed trait Event derives Codec.AsObject
  |                                 ^
  |no implicit argument of type deriving.Mirror.Of[Event] @InlineParam was found for parameter A of method derived in trait CodecDerivation

Any info appreciated.

Tushar Mathur
@tusharmath
Is there a better way to reduce this boilerplate —
  implicit def decoder: Decoder[Client] =
      List[Decoder[Client]](
        decoderGqlStart.prepare(_.downField("GQL_START")).widen,
        deriveDecoder[GQL_CONNECTION_INIT].prepare(_.downField("GQL_CONNECTION_INIT")).widen,
        deriveDecoder[GQL_STOP].prepare(_.downField("GQL_STOP")).widen,
        deriveDecoder[GQL_CONNECTION_TERMINATE].prepare(_.downField("GQL_CONNECTION_TERMINATE")).widen
      ).reduceLeft(_ or _)
Zeshan Ali
@zeshansali

Hey all, I’m trying to spin up a small API using http4s and circe. I’m running into an issue when trying to encode a simple case class using automatic derivation. The code is:

import java.{util => ju}

import cats._
import cats.effect._
import cats.implicits._
import doobie._
import doobie.free.Embedded.Connection
import doobie.implicits._
import doobie.postgres._
import doobie.postgres.implicits._
import doobie.util.ExecutionContexts
import io.circe._
import io.circe.generic.auto._
import io.circe.literal._
import io.circe.syntax._
import org.http4s._
import org.http4s.dsl.io._
import org.http4s.implicits._
import org.http4s.server.blaze._
import org.http4s.server.Router

case class User(firstName: String,
                lastName: String,
                birthday: ju.Date,
                email: String,
                createdAt: String,
                updatedAt: String)

trait UserRepo {
  def getUser(id: String): IO[User]
}

case class UserRepoImpl(xa: Transactor[IO]) extends UserRepo {
  override def getUser(id: String): IO[User] = {
    sql"""
          |select first_name,
          |       last_name,
          |       birthday,
          |       email,
          |       created_at,
          |       updated_at
          |  from users
          | where id = ${ju.UUID.fromString(id)}
          |
       """.stripMargin
          .query[User]
          .unique
          .transact(xa)
  }      
}

object UserRoutes {
  def get(userRepo: UserRepo): HttpRoutes[IO] = {
    HttpRoutes.of[IO] {
      case GET  -> Root / id => {
        userRepo.getUser(id).flatMap(user => Ok(user.asJson))
      }
    }
  }
}

object Main extends IOApp {
  implicit val cs = IO.contextShift(ExecutionContexts.synchronous)

  val xa = Transactor.fromDriverManager[IO]("org.postgresql.Driver", "jdbc:postgresql:local", "postgres", "password")
  val userRepo: UserRepo = UserRepoImpl(xa)

  val httpApp = Router(
    "/api/v1/users" -> UserRoutes.get(userRepo)
  ).orNotFound

  def run(args: List[String]): IO[ExitCode] =
    BlazeServerBuilder[IO]
      .bindHttp(8080, "localhost")
      .withHttpApp(httpApp)
      .serve
      .compile
      .drain
      .as(ExitCode.Success)
}

I get the following error when I try to compile (via sbt):

could not find implicit value for parameter encoder: io.circe.Encoder[com.zsali.User]
         userRepo.getUser(id).flatMap(user => Ok(user.asJson))

I think I’m doing everything the docs mention for automatic derivation, but can’t tell if I’m missing something. Can anyone help me understand what I’m doing wrong? I’m using circe 0.13.0 and Scala 2.13.2. Thanks!

ybasket
@ybasket
@zeshansali circe doesn’t come with an Encoder for java.util.Date, so define your own or use java.time.LocalDate
ComFreek
@ComFreek
I am running into a stack overflow with the Scala compiler when compiling some code with nested case classes and io.circe.generic.auto._.
I tried increasing the stack size -- as mentioned in the docs: https://circe.github.io/circe/codecs/known-issues.html -- to no avail.
To be precise, I tried increasing it in IntelliJ's settings pane (the IntelliJ project is imported from an SBT build file). I am not entirely sure that IntelliJ picks that up.
ComFreek
@ComFreek
I now tried the native SBT shell. Same error: https://pastebin.com/frNLSVhj
I had set the stack size via javaOptions in Global ++= Seq("-Xmx2g", "-Xss512m") in my build.sbt.
ComFreek
@ComFreek
Is there any way to circumvent the problem?
I have now tried to provide explicit implicits implicit val enc = Encoder[MyCaseClass], implicit val dec = Encoder[MyCaseClass]. It works in IntelliJ (only by coincidence?), but not from the SBT shell.
Zeshan Ali
@zeshansali
@ybasket That worked - thanks for the help.
Felix Palludan Hargreaves
@hejfelix
Can I compose multiple Plated transformations such that I don't have to traverse the structure multiple times?
Alex Antonov
@antonoal
Hi. I've just updated the libs versions on my project and got java.lang.NoSuchMethodError: fs2.Pull$.stream$extension(Lfs2/internal/FreeC;)Lfs2/internal/FreeC;. I believe it's cause by the fact that circe-fs2 v 0.13 is built against fs2 v2.2.2. Is there a release planned built for fs2 v 2.4.x any time soon or should I hold on with the upgrade?
Gavin Bisesi
@Daenyth
Sounds more like an error in fs2 that 2.4 breaks bincompat with 2.2
:eyes: yes fs2 2.4 says it's binary compatible with previous 2.x releases
Damian van Beekum
@theejazz
Hi! I've been having trouble trying out automated decoding. I keep getting a DecodingFailure, specifically "Attempt to decode value on failed cursor, List(DownField(hits))" where 'hits' is a key in my JSON. Interestingly, the key it prints often appears to be the very last item in my JSON (It's not always, but that might be a caching issue). Any suggestions as to how I might fix this? Below is a simple example that produces this result for me:
import io.circe.generic.auto._
import io.circe.parser.decode

case class Request(meta: Meta, response: Response)
case class Meta(status: Int, message: Option[String])
case class Response(hits: String)

object RequestDecoder {
  def main(args: Array[String]): Unit = {
    val request = """{"meta":{"status":200},"response":{"hits":"hi"}}"""
    println(decode[Response](request))
  }
}
Yilin Wei
@yilinwei
@theejazz I'm on a phone so the formatting may be off, but isn't that a Request rather than a Response?
Alex Antonov
@antonoal
I'll raise it with fs2, thanks @Daenyth
Alex Antonov
@antonoal
Actually it's my mistake - no issue with fs2
Damian van Beekum
@theejazz
@yilinwei wow I'm genuinely facepalming right now... Thanks!
Ashwin Bhaskar
@ashwinbhaskar

I start getting this error after adding http4s-circe dependency.

 The json interpolator requires jawn to be available at compile time
[error]         val expectedJson = json"""

Why does this happen and how can i resolve it?

Gavin Bisesi
@Daenyth
Add jawn at % Compile scope
Tharun Kumar Kapse
@tkapse
Hi All, I am trying to decode JsonArray with ~900 objects where it complains with malformed json error. When I reduce the json count to ~110 objects it works properly. I am trying to understand is there any limit on no. of object in an array or is it the data size that's causing this issue?
cld u please help me out
Ashwin Bhaskar
@ashwinbhaskar
@Daenyth but it worked before I introduced http-circedependency.
Gavin Bisesi
@Daenyth
weird. I don't know
Damian van Beekum
@theejazz
Does Circe have a way of unifying the two statements below to remove path duplication? (custom decoding)
id <- c.downField("result").downField("group").downField("id").as[Int]
name <- c.downField("result").downField("group").downField("name").as[String]
Gavin Bisesi
@Daenyth
group = c.downField("result").downField("group")
id <- group.downField("id").as[Int]
name <- group.downField("name").as[String]
?
or maybe consider using the JsonPath optics, they're pretty sweet for code readability if not necessarily as great for error messages
Travis Brown
@travisbrown
@tkapse there are no size limits (unless you explicitly opt in to limited number sizes for safety reasons). If you run the same object through a JSON linter or something like jq there are no errors?
@ashwinbhaskar that sounds likely to be a version mismatch (http4s bringing in a newer or older version of jawn than one you’re getting from e.g. circe-parser).
2 replies
Damian van Beekum
@theejazz
@Daenyth Thanks! Tried that initially but turns out I had some scope problems. Will definitely look into JsonPath
Tharun Kumar Kapse
@tkapse
@travisbrown - when I trim the json and post with size 64KB its able to decode.. If i add one more object to json array it starts complaining with invalid json
the entire json size is around 500KB
Travis Brown
@travisbrown
@tkapse but do other JSON parsers handle the full version? just to eliminate the possibility of unrelated malformedness.
@tkapse also IIRC there are various JVM restrictions on strings at 64K
If you have a minimisation I'd be happy to take a look
Tharun Kumar Kapse
@tkapse
@travisbrown I tried one of online json validators and it was able to parse it..
Travis Brown
@travisbrown
:thumbsup:
Tharun Kumar Kapse
@tkapse
{
"first_name": "tharun",
"last_name": "kapse",
"gender": "male",
"address": {
"flat_no": "XXXX",
"street": "XXXX",
"address_line1": "XXXX",
"address_line2": "XXXX",
"city": "XXXX",
"Landmarks": [
],
"others": {},
"city": "XXXX",
"State": "XXXX"
},
"email": "XXXX"
}
each object would look something like this
in the array
Jente Hidskes
@Hjdskes
Given a Decoder, is it possible to retrieve the discriminator used in this decoder, if any?
Travis Brown
@travisbrown
@Hjdskes you could have a subtype of Decoder that carries around extra structure / info like that, but it's not currently provided.
Jente Hidskes
@Hjdskes
@travisbrown Thanks :)
Michael Sluyter
@msluyter
Hi. Pretty much of a newbie question. I was just attempting the Quick Start section of the docs and get the following:
[info] Starting scala interpreter...
Welcome to Scala 2.13.3 (Java HotSpot(TM) 64-Bit Server VM, Java 11.0.7).
Type in expressions for evaluation. Or try :help.

scala> import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
     |
import io.circe._
import io.circe.generic.auto._
import io.circe.parser._
import io.circe.syntax._

scala> sealed trait Foo
     |
trait Foo

scala> case class Bar(xs: Vector[String]) extends Foo
     |
class Bar

scala> case class Qux(i: Int, d: Option[Double]) extends Foo
     |
class Qux

scala> val foo: Foo = Qux(13, Some(14.0))
     |
val foo: Foo = Qux(13,Some(14.0))

scala> val json = foo.asJson.noSpaces
     |
                      ^
       error: Internal error: unable to find the outer accessor symbol of class

basically just cut & pasted the code from the example. I did add

scalacOptions ++= Seq("-Ymacro-annotations")

to my build.sbt

Anyone seen this before and/or have any ideas?