GithubHelp home page GithubHelp logo

Comments (5)

iyfedorov avatar iyfedorov commented on June 28, 2024 2

#2138

from circe.

zarthross avatar zarthross commented on June 28, 2024 1

The behavior is as expected. 'semi-auto' derivation should not do nested case classes.

from circe.

zorba128 avatar zorba128 commented on June 28, 2024

see also #2248

from circe.

zarthross avatar zarthross commented on June 28, 2024

#2138 should fix this.

from circe.

alycklama avatar alycklama commented on June 28, 2024

I can confirm this issue seems to be resolved.

However, I need to add an additional decoder for Location to make it work.

Updated Code

package org.my

import cats.implicits._
import io.circe._
import io.circe.generic.semiauto._
import io.circe.parser.decode

object Main extends App {
  case class Location(city: String)
  case class Person(name: String, location: Location)

  val jsonString =
    """{
      | "name": "John",
      | "location": {
      | }
      |}""".stripMargin

  implicit val locationDecoder: Decoder[Location] = deriveDecoder[Location]
  implicit val personDecoder: Decoder[Person] = deriveDecoder[Person]

  val result = decode[Person](jsonString)
  println(result)
  println(result.left.map(_.show))
}

Output

Left(DecodingFailure at .location.city: Missing required field)
Left(DecodingFailure at .location.city: Missing required field)

Ommitting Location Decoder

For some reason, it's no longer possible to derive nested case classes. You'll end up with the error below:

Could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[org.my.Main.Person]

I'll close this issue, as the issue has been resolved. It would be nice if the error was more precise, though. It's not the Person but the Location which could not be found.

from circe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.