简体   繁体   中英

Json4s Jackson read write case class not equal

How can this be that a previously serialised and then deserialised case class is not equal:

import org.json4s.DefaultFormats
import org.json4s.jackson.Serialization.{write, read}
implicit val formats: DefaultFormats = DefaultFormats

case class MyCaseTestClass(two: String, num: Int)
read[MyCaseTestClass](write(MyCaseTestClass("bla", 123))) shouldBe MyCaseTestClass("bla", 123)

And running this I get:

MyCaseTestClass(bla,123) was not equal to MyCaseTestClass(bla,123)
ScalaTestFailureLocation: ...
Expected :MyCaseTestClass(bla,123)
Actual   :MyCaseTestClass(bla,123)

Ok, after trying around a while I found that defining a case class inside your unit test class that is enriched with FlatSpec with Matchers this causes the issue somehow.

If defining the class outside, eg in a separate file / object, this doesn't happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM