Skip to content

Instantly share code, notes, and snippets.

@chronodm
Last active December 31, 2015 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chronodm/7994432 to your computer and use it in GitHub Desktop.
Save chronodm/7994432 to your computer and use it in GitHub Desktop.
Demonstrating a bug in json4s Reflector (or possibly just in Scala reflection) that produces a spurious IncompatibleClassChangeError when faced with locally declared case classes
import org.json4s._
import org.json4s.Extraction._
import org.scalatest.{Matchers, FlatSpec}
import org.json4s.native.Serialization
import org.json4s.native.Serialization._
/**
* @version $Id$ $Rev$ $Date$
*/
class MyClass(v: String) {
def myV = v
}
class MySerializer extends Serializer[MyClass] {
def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
case m: MyClass => decompose(m.myV)
}
/** Deserialization not supported */
def deserialize(implicit format: Formats) = PartialFunction.empty
}
class MySerializerSpec extends FlatSpec with Matchers {
implicit val formats = Serialization.formats(NoTypeHints) + new MySerializer
"MySerializer" should "serialize case classes with MyClass values" in {
case class Foo(bar: MyClass)
val foo = Foo(new MyClass("baz"))
val actual: String = write(foo)
val expected: String = "{\"bar\":\"baz\"}"
actual should be(expected)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment