Skip to content

Commit

Permalink
Fix #1107 by adding missing support of collections as types of value …
Browse files Browse the repository at this point in the history
…and "one value" classes
  • Loading branch information
plokhotnyuk committed Jan 21, 2024
1 parent 051fc74 commit 8e102b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2809,7 +2809,9 @@ object JsonCodecMaker {
else if (tpe =:= TypeRepr.of[ZoneOffset]) '{ $out.writeVal(${m.asExprOf[ZoneOffset]}) }
else if (isValueClass(tpe)) {
val vtpe = valueClassValueType(tpe)
genWriteVal(Select(m.asTerm, valueClassValueSymbol(tpe)).asExpr, vtpe :: types, isStringified, None, out)
vtpe.asType match
case '[vt] =>
genWriteVal(Select(m.asTerm, valueClassValueSymbol(tpe)).asExprOf[vt], vtpe :: types, isStringified, None, out)
} else if (isOption(tpe, types.tail)) {
val tpe1 = typeArg1(tpe)
tpe1.asType match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ case class UserId(id: String) extends AnyVal

case class OrderId(value: Int) extends AnyVal

case class UserIds(l: List[String]) extends AnyVal

object Alias {
type I = Int

Expand Down Expand Up @@ -1198,6 +1200,9 @@ class JsonCodecMakerSpec extends VerifyingSpec {
verifySerDeser(make[ValueClassTypes],
ValueClassTypes(UserId("123abc"), OrderId(123123)), """{"uid":"123abc","oid":123123}""")
}
"serialize and deserialize collection fields of value classes" in {
verifySerDeser(make[UserIds], UserIds(List("VVV", "WWW")), """["VVV","WWW"]""")
}
"serialize and deserialize top-level value classes" in {
verifySerDeser(make[UserId], UserId("123abc"), """"123abc"""")
verifySerDeser(make[OrderId], OrderId(123123), "123123")
Expand Down Expand Up @@ -1241,6 +1246,12 @@ class JsonCodecMakerSpec extends VerifyingSpec {
verifySerDeser(make[Array[OrderId]](CodecMakerConfig.withInlineOneValueClasses(true)),
_root_.scala.Array(OrderId(123123), OrderId(123456)), "[123123,123456]")
}
"serialize and deserialize collection fields of one value classes" in {
case class UserIds(l: List[String])

verifySerDeser(make[UserIds](CodecMakerConfig.withInlineOneValueClasses(true)),
UserIds(List("VVV", "WWW")), """["VVV","WWW"]""")
}
"serialize and deserialize case classes with options" in {
verifySerDeser(codecOfOptions,
Options(Option("VVV"), Option(BigInt(4)), Option(Set()), Option(1L), Option(_root_.java.lang.Long.valueOf(2L)),
Expand Down

0 comments on commit 8e102b5

Please sign in to comment.