Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
simplistic implementation of `toMap`
- Loading branch information
|
@@ -12,7 +12,7 @@ class MappableTest extends WordSpec with Matchers { |
|
|
"simple case class" should { |
|
|
"deserialise to map" in { |
|
|
val testInstance = SimpleCaseClass(i = 42, s = "something") |
|
|
testInstance.toMap shouldBe 'empty |
|
|
testInstance.toMap shouldBe Map("i" -> 42, "s" -> "something") |
|
|
} |
|
|
} |
|
|
|
|
|
|
@@ -8,9 +8,14 @@ class mappable extends StaticAnnotation { |
|
|
inline def apply(defn: Any): Any = meta { |
|
|
val q"..$mods class $tName (..$params) extends $template" = defn |
|
|
|
|
|
val keyValues: Seq[Term] = params.map { param => |
|
|
val memberName = Term.Name(param.name.value) |
|
|
q"${param.name.value} -> $memberName" |
|
|
} |
|
|
|
|
|
val res = q""" |
|
|
..$mods class $tName(..$params) { |
|
|
def toMap(): Map[String, Any] = Map.empty[String, Any] |
|
|
def toMap(): Map[String, Any] = Map[String, Any](..$keyValues) |
|
|
} |
|
|
""" |
|
|
|
|
|