Skip to content

Commit 7149e62

Browse files
committed
Fix #92 by enforcing the type information completeness and availability of annotations
1 parent fc8df0d commit 7149e62

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

macros/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,11 @@ object JsonCodecMaker {
299299
case class FieldAnnotations(name: String, transient: Boolean, stringified: Boolean)
300300

301301
def getFieldAnnotations(tpe: Type): Map[String, FieldAnnotations] = tpe.members.collect {
302-
case m: TermSymbol if m.annotations.exists(a => a.tree.tpe =:= typeOf[named]
303-
|| a.tree.tpe =:= typeOf[transient] || a.tree.tpe =:= typeOf[stringified]) =>
302+
case m: TermSymbol if {
303+
m.info // to enforce the type information completeness and availability of annotations
304+
m.annotations.exists(a => a.tree.tpe =:= typeOf[named] || a.tree.tpe =:= typeOf[transient] ||
305+
a.tree.tpe =:= typeOf[stringified])
306+
} =>
304307
val fieldName = m.name.decodedName.toString.trim // FIXME: Why is there a space at the end of field name?!
305308
val named = m.annotations.filter(_.tree.tpe =:= typeOf[named])
306309
if (named.size > 1) fail(s"Duplicated '${typeOf[named]}' defined for '$fieldName' of '$tpe'.")

macros/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMakerSpec.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ class JsonCodecMakerSpec extends WordSpec with Matchers {
115115

116116
case class Operators(`=<>!#%^&|*/\\~+-:$`: Int)
117117

118-
//FIXME: case classes with field annotation(s) should be defined in source file before `make` call for them
119-
case class NameOverridden(@named("new_" + "name") oldName: String)
120-
121118
val codecOfNameOverridden: JsonValueCodec[NameOverridden] = make[NameOverridden](CodecMakerConfig())
122119

123120
case class Stringified(@stringified i: Int, @stringified bi: BigInt, @stringified l1: List[Int], l2: List[Int])
@@ -1158,4 +1155,6 @@ class JsonCodecMakerSpec extends WordSpec with Matchers {
11581155
}
11591156

11601157
def toString(json: Array[Byte]): String = new String(json, 0, json.length, UTF_8)
1161-
}
1158+
}
1159+
1160+
case class NameOverridden(@named("new_" + "name") oldName: String) // intentionally declared after the `make` call

0 commit comments

Comments
 (0)