Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonCodec ≠ JsonDecoder + JsonEncoder: could not find JsonCodec.Typeclass for type String #167

Open
guizmaii opened this issue Feb 7, 2021 · 3 comments

Comments

@guizmaii
Copy link
Member

guizmaii commented Feb 7, 2021

Hi everyone,

I hope it's not too early to report things.

I tried to replace Circe in a Scala/ScalaJS project and I had the following errors:

[error] /Users/jules.ivanic/jules_ivanic/workspace/http4s-laminar-stack/modules/shared/src/main/scala/example/shared/Protocol.scala:10:70: magnolia: could not find JsonCodec.Typeclass for type String
[error]     in parameter 'search' of product type example.shared.Protocol.GetSuggestions.Request
[error]       implicit final val codec: JsonCodec[Request] = DeriveJsonCodec.gen
[error]                                                                      ^
[error] /Users/jules.ivanic/jules_ivanic/workspace/http4s-laminar-stack/modules/shared/src/main/scala/example/shared/Protocol.scala:15:71: magnolia: could not find JsonCodec.Typeclass for type Seq[String]
[error]     in parameter 'suggestions' of product type example.shared.Protocol.GetSuggestions.Response
[error]       implicit final val codec: JsonCodec[Response] = DeriveJsonCodec.gen
[error]                                                                       ^
[error] two errors found

It's open-source so you can easily reproduce it. See: https://github.com/keynmol/http4s-laminar-stack/pull/4/files

@fsvehla
Copy link
Contributor

fsvehla commented Mar 9, 2021

Hello, @guizmaii

I hope it’s not too late to respond :)

I have to dive deeper but there seems to be some issue with DeriveJsonCodec which does not happen when using Encoder + Decoder separately.

If you want to continue to work in the meantime, this encoding works:

package example.shared

import zio.json._

object Protocol {
  object GetSuggestions {

    final case class Request(search: String, prefixOnly: Option[Boolean] = None)
    object Request {
      implicit final val encoder: JsonEncoder[Request] = DeriveJsonEncoder.gen
      implicit final val decoder: JsonDecoder[Request] = DeriveJsonDecoder.gen
    }

    final case class Response(suggestions: Seq[String])
    object Response {
      implicit final val encoder: JsonEncoder[Response] = DeriveJsonEncoder.gen
      implicit final val decoder: JsonDecoder[Response] = DeriveJsonDecoder.gen
    }
  }
}

@fsvehla fsvehla changed the title [ScalaJS] magnolia: could not find JsonCodec.Typeclass for type String JsonCodec ≠ JsonDecoder + JsonEncoder: could not find JsonCodec.Typeclass for type String Mar 9, 2021
@guizmaii
Copy link
Member Author

guizmaii commented Mar 9, 2021

@fsvehla Thanks! 🙏

@paulpdaniels
Copy link
Contributor

Was there any resolution of this in the latest versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants