Permalink
Browse files

Unmangle names when using FieldSerializer

  • Loading branch information...
1 parent 5d843c9 commit 1f99c25d89ac0b995894e2c9b3904b50d8992c4a Joni Freeman committed Jun 16, 2011
@@ -92,8 +92,9 @@ object Extraction {
case args =>
val fields = formats.fieldSerializer(x.getClass).map { serializer =>
Reflection.fields(x.getClass).map {
- case (n, _) =>
- val fieldVal = Reflection.getField(x, n)
+ case (mangledName, _) =>
+ val n = Meta.unmangleName(mangledName)
+ val fieldVal = Reflection.getField(x, mangledName)
val s = serializer.serializer orElse Map((n, fieldVal) -> Some(n, fieldVal))
s((n, fieldVal)).map { case (name, value) => JField(name, decompose(value)) }
.getOrElse(JField(n, JNothing))
@@ -33,5 +33,15 @@ object FieldSerializerBugs extends Specification {
atomic.get mustEqual 1
}
*/
+
+ "Name with symbols is correctly serialized" in {
+ implicit val formats = DefaultFormats + FieldSerializer[AnyRef]()
+
+ val s = WithSymbol(5)
+ val str = Serialization.write(s)
+ str mustEqual """{"a-b*c":5}"""
+ read[WithSymbol](str) mustEqual s
+ }
}
+case class WithSymbol(`a-b*c`: Int)

0 comments on commit 1f99c25

Please sign in to comment.