jsoniter-scala
jsoniter-scala copied to clipboard
Compilation error during cross builds
I have the following class hierarchy:
import com.github.plokhotnyuk.jsoniter_scala.macros._
import com.github.plokhotnyuk.jsoniter_scala.core._
final case class Container(a: Option[Int], b: Option[String], src: Source)
object Container {
implicit val codec: JsonValueCodec[Container] =
JsonCodecMaker.make(CodecMakerConfig.withDiscriminatorFieldName(None))
}
sealed trait Source
object Source {
case object A extends Source
case object B extends Source
case object C extends Source
}
While it seems to pass tests and work for single scala version, trying to do the cross-version publish (or any other cross-version task) fails with:
Cannot evaluate a parameter of the 'make' macro call for type
I know this is a known type of error, but what would be the recommended way to overcome this issue?
Please find a minimal failing example here. Running a simple +publishLocal should fail with the described error.
As a workaround, please use the JsonCodecMaker.makeWithoutDiscriminator macro call (that is available since v2.6.0) instead of JsonCodecMaker.make(CodecMakerConfig.withDiscriminatorFieldName(None))
@plokhotnyuk makeWithoutDiscriminator worked as a charm! Many thanks for prompt fix! :clap: :tada:
Reopening because the source of the problem (using of Eval.eval for passing of parameters to the make macro that can be used in the compile-time) is not fixed yet.
The full list of Eval.eval calls used in the jsoniter-scala library are listed here: https://github.com/scalacenter/scala-3-migration-guide/pull/11
Yet another workaround that could help for other configurations of derivation is adding intermediate +compile:

just encountered this issue during casual publish without compile step before it, and it seems to be linked.
[error] java.lang.AssertionError: assertion failed: pkgClass = package <root>, sym = package com, existing = package com (depth=0)
[error] protected implicit val ErrorBodyCodec: JsonValueCodec[ErrorBody] = JsonCodecMaker.make(SearchModelConfig)
[error]
But I am using quite old version 2.4. At first I thought it's an issue with SBT, but this is actually jsoniters fault?
Thanks