Last active
December 31, 2015 13:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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