diff --git a/implicits/src-3/upickle/implicits/macros.scala b/implicits/src-3/upickle/implicits/macros.scala index ea98de02f..bd3a74cd3 100644 --- a/implicits/src-3/upickle/implicits/macros.scala +++ b/implicits/src-3/upickle/implicits/macros.scala @@ -51,10 +51,11 @@ end extractKey inline def fieldLabels[T] = ${fieldLabelsImpl[T]} def fieldLabelsImpl0[T](using Quotes, Type[T]): List[String] = import quotes.reflect._ - val fields: List[Symbol] = TypeTree.of[T].symbol + val fields: List[Symbol] = TypeRepr.of[T].typeSymbol .primaryConstructor .paramSymss .flatten + .filterNot(_.isType) fields.map{ sym => extractKey(sym) match { diff --git a/upickle/test/src/upickle/example/ExampleTests.scala b/upickle/test/src/upickle/example/ExampleTests.scala index bd6f425ba..2eb48e90b 100644 --- a/upickle/test/src/upickle/example/ExampleTests.scala +++ b/upickle/test/src/upickle/example/ExampleTests.scala @@ -78,6 +78,13 @@ object Custom2{ ) } } +object Generic { + case class Container[T](a: T) + object Container{ + implicit val intRW: RW[Container[Int]] = macroRW + } +} + import KeyedTag._ import Keyed._ @@ -569,6 +576,23 @@ object ExampleTests extends TestSuite { writeBinary(Array[Byte](1, 2, 3, 4)) ==> Array(0xc4.toByte, 4, 1, 2, 3, 4) readBinary[Array[Byte]](Array[Byte](0xc4.toByte, 4, 1, 2, 3, 4)) ==> Array(1, 2, 3, 4) } + test("generic"){ + import upickle.default._ + import Generic._ + test("read") - { + val containerJson = """{"a":3}""" + val parsed = read[Container[Int]](containerJson) + val expected = Container[Int](3) + assert(parsed == expected) + } + + test("write") - { + val original = Container[Int](3) + val serialized = write(original) + val expected = """{"a":3}""" + assert(serialized == expected) + } + } } }