Questions tagged [circe]

Circe is a JSON library for Scala (and Scala.js).

Circe is a JSON library for Scala powered by Cats.

A simple usage of this library is:

import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._

sealed trait Foo
case class Bar(xs: Vector[String]) extends Foo
case class Qux(i: Int, d: Option[Double]) extends Foo

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

val json = foo.asJson.noSpaces
println(json) // prints: {"Qux":{"i":13,"d":14}}

val decodedFoo = decode[Foo](json)
println(decodedFoo) // prints: Right(Qux(13,Some(14)))

For reading about it please refer:

328 questions
0
votes
1 answer

Need help decoding following json with Circe

I'm trying to parse nested JSON object with Circe library. I would like to map it to flat case class ignoring some of the fields. import io.circe.generic.auto._ import io.circe.{Decoder, Encoder, HCursor, Json} val jsonString = """{ "parent" : { …
marcin_koss
  • 5,375
  • 8
  • 40
  • 56
0
votes
2 answers

Organizing Scala implicits associated with a type

I'd like to introduce some types to represent possible values of a field in a larger type. This fields needs to be possible to encode/decode to/from JSON and also be able to be written/read to a database. I'm still new to Scala and the type I would…
beta
  • 2,177
  • 17
  • 29
0
votes
1 answer

Why isn't my discriminating field being added to my encoded case object using circe?

I have the following code, which I expect to print the type of object being encoded, but it only prints an empty object: import cats.syntax.functor._ import io.circe.generic.auto._ import io.circe.generic.extras.Configuration import…
erip
  • 13,935
  • 9
  • 51
  • 102
0
votes
0 answers

Encoding java.lang.Class[T] and Vector[_ <: Object]

When writing a RPC framework, we need to code the Request and Response class, here is my Request class: trait Servicable {} // a marking Trait for the services case class Request[T <: Servicable]( id: String, serviceClazz: Class[T], …
Ukonn Ra
  • 695
  • 5
  • 16
0
votes
1 answer

How to parse an variant Json using Circe library with Scala?

I'm trying to create a decoder for my Json model using case classes but i cannot find the way to decode a variant list of jsons. object CirceTester { def main(args: Array[String]): Unit = { val json = """{ "foo": "bar", "baz": "123.34", …
0
votes
1 answer

Decoding a Seq of objects using Circe

I have two classes that look something like that import io.circe.Decoder case class FactResponse(id: String, status: String) { ... } object FactResponse { implicit val decoder: Decoder[FactResponse] = Decoder.forProduct2("id",…
Niro
  • 353
  • 2
  • 19
0
votes
0 answers

How to Decode a sealed trait to JSON - Circe

I have the sealed trait below and its case class and I would like to transform it into JSON to give it as a response in my Akka Http app. sealed trait HttpRestError { val statusCode: StatusCode val code: String val message: String } case…
pik4
  • 1,123
  • 1
  • 18
  • 46
0
votes
2 answers

Circe : Serialize case class body fields to JSON

I have a case class with some val (which is not a constructor param). How can I get those fields also in the generated json ? I was using Json4s before, and used FieldSerializer which did this trick. But unable to get this with Circe. What I want is…
Yadu Krishnan
  • 3,182
  • 1
  • 36
  • 74
0
votes
1 answer

Circe decode case class

I have a case class as following: case class Road(id: String, light: TrafficLight, cars: Map[String, String]) Simply, I'm trying to decode Json to List[Road]. The Json I'm trying to decode is: [ { "id" = "A", "light" =…
Doe
  • 1
  • 1
0
votes
2 answers

Decode incomplete ADT with Circe

For a case class Apple(color:String, sweetness:Double) I can define a Decoder[String => Apple] via generic.(semi)auto or generic.extras.(semi)auto, However for a sealed trait hierarchy (an ADT) I cannot: sealed trait Fruit { def…
eirirlar
  • 795
  • 5
  • 23
0
votes
1 answer

Circe list deserialization with best-attempt and error reporting

I'm using Circe to deserialize json containing a list. Sometimes a few items in the json list are corrupted, and that causes the entire deserialization to fail. Instead, I want Circe to make a best attempt, and to return a list of all the…
thund
  • 1,494
  • 1
  • 17
  • 28
0
votes
1 answer

Wrapping circe decoder with own codecs (implicits)

I am using the semi-automatic decoder derivation that circe provides via deriveDecoder. There are some custom ADT that I have where I'd like to pass my own decoder for circe to use when it resolves the implicit decoders. package object json { …
Cheetah
  • 12,515
  • 28
  • 93
  • 167
0
votes
1 answer

How to resolve ambiguous implicit values in Scala for parsing JSON in Play Json?

I'm getting an error ScalaFiddle.scala:45: error: ambiguous implicit values: both getter _ewriter in module class ScalaFiddle of type => json.this.Reads[ScalaFiddle.this.SportJSON] and getter _jwriter in module class ScalaFiddle of type =>…
0
votes
1 answer

Deserialize JSON based on Field in Payload in Scala

I have a similar question with Deserialize json based on fields in .Net (C#), but do it in Scala. I have an app which streams in 2 types of json objects (Account and User). Account: { "data_type": "account", "id": 1, "type": "Trial", …
gyoho
  • 619
  • 1
  • 8
  • 20
0
votes
1 answer

Custom decoder for AWS API Gateway using circe

I would like to create a custom decoder for AWS API Gateway using circe-core. I have the following code: case class APIGatewayInput(body:Result[Body], queryParams: Map[String,String], pathParams: Map[String,String]) object ApiGatewayInput { …
vamsiampolu
  • 5,355
  • 15
  • 65
  • 161
1 2 3
21
22