Skip to content

Commit a96f7dc

Browse files
committed
Fix unwanted trimming of whitespaces for backtiked field names in Scala 2 macros
1 parent f23ddd2 commit a96f7dc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

jsoniter-scala-macros/shared/src/main/scala-2/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ object JsonCodecMaker {
609609

610610
def decodeName(s: Symbol): String = NameTransformer.decode(s.name.toString)
611611

612+
def decodeFieldName(s: Symbol): String = NameTransformer.decode(s.name.toString.trim) // FIXME: Why is there a space at the end of field name?!
613+
612614
def resolveConcreteType(tpe: Type, mtpe: Type): Type = {
613615
val tpeTypeParams =
614616
if (tpe.typeSymbol.isClass) tpe.typeSymbol.asClass.typeParams
@@ -820,7 +822,7 @@ object JsonCodecMaker {
820822
val getters = tpe.members.collect { case m: MethodSymbol if m.isParamAccessor && m.isGetter => m }
821823
val annotations = tpe.members.collect {
822824
case m: TermSymbol if hasSupportedAnnotation(m) =>
823-
val name = decodeName(m).trim // FIXME: Why is there a space at the end of field name?!
825+
val name = decodeFieldName(m)
824826
val named = m.annotations.filter(_.tree.tpe =:= typeOf[named])
825827
if (named.size > 1) fail(s"Duplicated '${typeOf[named]}' defined for '$name' of '$tpe'.")
826828
val trans = m.annotations.filter(a => a.tree.tpe =:= typeOf[transient] ||

jsoniter-scala-macros/shared/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerSpec.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -2136,9 +2136,9 @@ class JsonCodecMakerSpec extends VerifyingSpec {
21362136
WriterConfig.withEscapeUnicode(true))
21372137
}
21382138
"serialize and deserialize case classes with Scala operators in field names" in {
2139-
case class Operators(`=<>!#%^&|*/\\~+-:$`: Int)
2139+
case class Operators(` =<>!#%^&|*/\\~+-:$ `: Int)
21402140

2141-
verifySerDeser(make[Operators], Operators(7), """{"=<>!#%^&|*/\\~+-:$":7}""")
2141+
verifySerDeser(make[Operators], Operators(7), """{" =<>!#%^&|*/\\~+-:$ ":7}""")
21422142
}
21432143
"don't serialize default values of case classes that defined for fields when the transientDefault flag is on (by default)" in {
21442144
val codecOfDefaults: JsonValueCodec[Defaults] = make

0 commit comments

Comments
 (0)