From dde18ac94db38b636284f8afded547a77f29da39 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 12 Jul 2024 09:27:40 +0800 Subject: [PATCH] Remove unnecessary case from annotation classes, consolidate `allowUnknownKeys` annotation (#606) Binary incompatible, needs to be done in 4.x --- upickle/core/src/upickle/core/Config.scala | 7 +++++++ .../src/upickle/implicits/CaseClassReadWriters.scala | 2 +- upickle/implicits/src/upickle/implicits/key.scala | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/upickle/core/src/upickle/core/Config.scala b/upickle/core/src/upickle/core/Config.scala index 66bb57c33..afd9ceda0 100644 --- a/upickle/core/src/upickle/core/Config.scala +++ b/upickle/core/src/upickle/core/Config.scala @@ -67,4 +67,11 @@ trait Config { * un-intuitiveness and verbosity */ def optionsAsNulls: Boolean = true + + /** + * Whether or not unknown keys when de-serializing case classes should be allowed. + * Defaults to `true`, but can be set to `false` to make the presence unknown keys + * raise an error + */ + def allowUnknownKeys: Boolean = true } diff --git a/upickle/implicits/src/upickle/implicits/CaseClassReadWriters.scala b/upickle/implicits/src/upickle/implicits/CaseClassReadWriters.scala index 6beb8e551..cd1480994 100644 --- a/upickle/implicits/src/upickle/implicits/CaseClassReadWriters.scala +++ b/upickle/implicits/src/upickle/implicits/CaseClassReadWriters.scala @@ -11,7 +11,7 @@ import upickle.core.{Abort, AbortException, ArrVisitor, NoOpVisitor, ObjVisitor, * package to form the public API1 */ trait CaseClassReadWriters extends upickle.core.Types{ - def allowUnknownKeys: Boolean = true + abstract class CaseClassReader[V] extends SimpleReader[V] { override def expectedMsg = "expected dictionary" diff --git a/upickle/implicits/src/upickle/implicits/key.scala b/upickle/implicits/src/upickle/implicits/key.scala index 6b9a02a2e..dc0efe19a 100644 --- a/upickle/implicits/src/upickle/implicits/key.scala +++ b/upickle/implicits/src/upickle/implicits/key.scala @@ -2,5 +2,5 @@ package upickle.implicits import scala.annotation.StaticAnnotation -case class key(s: String) extends StaticAnnotation -case class allowUnknownKeys(b: Boolean) extends StaticAnnotation \ No newline at end of file +class key(s: String) extends StaticAnnotation +class allowUnknownKeys(b: Boolean) extends StaticAnnotation \ No newline at end of file