You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala
+17-18Lines changed: 17 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -778,18 +778,13 @@ object JsonCodecMaker {
778
778
case _ =>false
779
779
}
780
780
781
-
defgenericTupleTypeArgs(tpe: TypeRepr):List[TypeRepr] = tpe match {
if (isGenericTuple(nTpe)) namedGenericTupleNames(nTpe)
997
-
else nameConstants.collect { caseConstantType(StringConstant(x)) => x }
998
-
valisGeneric= isGenericTuple(tTpe)
999
-
valtypes=
1000
-
if (isGeneric) genericTupleTypeArgs(tTpe)
1001
-
else typeArgs(tTpe)
989
+
caseAppliedType(_, List(nTpe, tTpe)) =>
990
+
// Borrowed from an amazing work of Aleksander Rainko: https://github.com/arainko/ducktape/blob/8d779f0303c23fd45815d3574467ffc321a8db2b/ducktape/src/main/scala/io/github/arainko/ducktape/internal/Structure.scala#L188-L199
991
+
valnames= tupleTypeArgs(nTpe.asType).map { caseConstantType(StringConstant(n)) => n }
992
+
valtypeArgs= tupleTypeArgs(tTpe.asType)
993
+
valsize= typeArgs.size
994
+
valtupleTpe=
995
+
if (size <=22) defn.TupleClass(size).typeRef.appliedTo(typeArgs)
Copy file name to clipboardExpand all lines: jsoniter-scala-macros/shared/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerNewTypeSpec.scala
+7-3Lines changed: 7 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -63,9 +63,13 @@ class JsonCodecMakerNewTypeSpec extends VerifyingSpec {
Copy file name to clipboardExpand all lines: jsoniter-scala-next-tests/shared/src/test/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerNamedTupleSpec.scala
+23-3Lines changed: 23 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,34 @@ class JsonCodecMakerNamedTupleSpec extends VerifyingSpec {
7
7
"JsonCodecMaker.make generate codecs which" should {
8
8
"serialize and deserialize Scala 3 named tuples" in {
9
9
verifySerDeser(make[(i: Int, s: String)], (i =1, s ="VVV"), """{"i":1,"s":"VVV"}""")
10
+
verifySerDeser(make[NamedTuple.Reverse[(i: Int, s: String)]], (s ="VVV", i =1), """{"s":"VVV","i":1}""")
11
+
verifySerDeser(make[NamedTuple.Concat[(i: Int), (s: String)]], (i =1, s ="VVV"), """{"i":1,"s":"VVV"}""")
12
+
verifySerDeser(make[NamedTuple.Tail[(l: Long, i: Int, s: String)]], (i =1, s ="VVV"), """{"i":1,"s":"VVV"}""")
13
+
verifySerDeser(make[NamedTuple.Init[(i: Int, s: String, l: Long)]], (i =1, s ="VVV"), """{"i":1,"s":"VVV"}""")
14
+
verifySerDeser(make[NamedTuple.Drop[(l: Long, i: Int, s: String), 1]], (i =1, s ="VVV"), """{"i":1,"s":"VVV"}""")
15
+
verifySerDeser(make[NamedTuple.Take[(i: Int, s: String, l: Long), 2]], (i =1, s ="VVV"), """{"i":1,"s":"VVV"}""")
0 commit comments