diff --git a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala index 688c9bc..300eacc 100644 --- a/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala +++ b/modules/core/src/main/scala-3/tethys/derivation/Derivation.scala @@ -398,7 +398,7 @@ private[derivation] class DerivationMacro(val quotes: Quotes) } ReaderError.wrongJson( "Can not extract fields from json: " + uninitializedFields - .mkString(", ") + .mkString("'", "', '", "'") )(${ fieldName }) } diff --git a/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala b/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala index 981dac1..5571234 100644 --- a/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala +++ b/modules/core/src/test/scala-3/tethys/derivation/DerivationSpec.scala @@ -20,6 +20,15 @@ class DerivationSpec extends AnyFlatSpec with Matchers { res } + it should "build message correctly" in { + case class Foo(bar: Int, baz: String, faz: Boolean) derives JsonReader + + util.Try(read[Foo](obj("bar" -> 1))) should matchPattern { + case util.Failure(ex) + if ex.getMessage == """Illegal json at '[ROOT]': Can not extract fields from json: 'baz', 'faz'""" => + } + } + it should "compile and correctly write and read product" in { case class Person( id: Int, diff --git a/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala index 2709dc0..37a7e40 100644 --- a/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala +++ b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala @@ -459,7 +459,7 @@ trait ReaderDerivation if($predicate) { val $uninitializedFields = new scala.collection.mutable.ArrayBuffer[String](${xs.size}) ..$fields - $readerErrorCompanion.wrongJson("Can not extract fields from json" + $uninitializedFields.mkString("'", "', '", "'")) + $readerErrorCompanion.wrongJson("Can not extract fields from json: " + $uninitializedFields.mkString("'", "', '", "'")) } """ } diff --git a/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala b/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala index e1ea2cc..88faccb 100644 --- a/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala +++ b/modules/macro-derivation/src/test/scala-2.13+/tethys/derivation/SemiautoReaderDerivationTest.scala @@ -21,6 +21,17 @@ class SemiautoReaderDerivationTest extends AnyFlatSpec with Matchers { behavior of "semiauto derivation" + + it should "build message correctly" in { + case class Foo(bar: Int, baz: String, faz: Boolean) + + implicit val reader: JsonReader[Foo] = tethys.derivation.semiauto.jsonReader + + util.Try(read[Foo](obj("bar" -> 1))) should matchPattern { + case util.Failure(ex) if ex.getMessage == """Illegal json at '[ROOT]': Can not extract fields from json: 'baz', 'faz'""" => + } + } + it should "derive readers for simple case class hierarchy" in { implicit val dReader: JsonReader[D] = jsonReader[D] implicit val cReader: JsonReader[C] = jsonReader[C]