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
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?
Travis Brown
@travisbrown
@msluyter ugh, I hadn't seen that particular one before, but the 2.13 patch releases have broken a ton of stuff in the REPL in general…
this one looks like it broke in 2.13.2.
it should be fine if you use :paste mode for the sealed trait and case classes
(i.e. enter :paste, copy and paste those lines, and then ctrl-D)
Michael Sluyter
@msluyter
using :paste worked, thanks @travisbrown!
Marcin Pucilowski
@Pucilowski
I'm using configured codecs from the extras package to serialize ADT hierarchies with a "type" property. Is there a way to supply a custom class<->string mapping for the value of this property? e.g. type StringDef maps to "string" , not "StringDef". Would it be easier to just type out my encoders/decoders manually?
Travis Brown
@travisbrown
@Pucilowski extras provides configuration options for transforming constructor names that should work
(Sorry, not at a computer at the moment, but if you look for “transform + constructor names” it should come up)
Ibrahim Moufti
@Mouftizo

Hello everyone : ) appologies in advance if this comes as a noob question as I am relatively new to Circe.

I have a JSON that looks like:

{
  "data": [
    {
      "id": "1",
      "email": "hello@world.com",
      "name": "Mr foo",
      "roles": [
        "Chief Bar Officer"
      ],
      "avatar_url": null,
      "phone_number": null
    },
    {
      "id": "2",
      "email": "bye@world.com",
      "name": "Mr baz",
      "roles": [
        "Chief Baz Officer"
      ],
      "avatar_url": null,
      "phone_number": null
    }
  ]
}

I am mainly interested in parsing/deserializing the data list, and I would like to do that manually (I prefer the manual way for some mysterious reason).

In case this is relevant, I am using sttp's circe library sttp.client.circe._ with the intention of parsing incoming data from get requests directly into Json using asJson.

A get sttp request looks something like:

val r1 = basicRequest
    .get(uri"https://woooo.woo.wo/v1/users")
    .header("accept", "application/json")
    .header("Authorization", "topsecret"
    .response(asJson[SomeClass])

This is what I have tried so far:

// Define the case class
case class User(
    id: String,
    email: String,
    name: String,
    roles: List[String],
    avatar_url: Option[String],
    phone_number: Option[String]
)

// Define the manual deserializer

case object User {

  implicit val userDecoder: Decoder[User] = (hCursor: HCursor) => {
    val data = hCursor.downField("data").downArray
    for {
      id <- data.get[String]("id")
      email <- data.get[String]("email")
      name <- data.get[String]("name")
      roles <- data.get[List[String]]("roles")
      avatarUrl <- data.get[Option[String]]("avatarUrl")
      phoneNumber <- data.get[Option[String]]("phoneNumber")
    } yield User(id, email, name, roles, avatarUrl, phoneNumber)
  }
}

The problem with my approach (I think) is that .downArray makes me only serialize the first User in the array of Users.

My objective is to be able to have some sequence of users (something like List[User] maybe), but at the moment I only end up deserializing one user in the array.

It is worth mentioning that the "data" array, does not contain a fixed-number of users, and every api call could result in a different number of users.

Travis Brown
@travisbrown
@Mouftizo it would be better to build up the instance you need to parse the top-level JSON object compositionally…
i.e. have a Decoder[User] that only decodes a single user JSON object, and then use Decoder[List[User]].at("data") or something similar to decode the top-level JSON object containing the data field with the JSON array.
Ibrahim Moufti
@Mouftizo
@travisbrown I thought of doing something like: val decodingResult = parser.decode[List[User]](incomingString) but I am using the sttp asJson , so not sure how to make that work with that (as I don't access the raw string). Not sure if that is 100% in line with what you suggested
Travis Brown
@travisbrown
@Mouftizo in that case you could do something like this:
case class Users(value: List[User])

object Users {
  implicit val decodeUsers: Decoder[Users] = Decoder[List[User]].at("data").map(Users(_))
}
6 replies
and then asJson[Users]
felher
@felher
Is there a reason that there is no emap on KeyDecoder, just map? Should errors not be possible on key decoders?