简体   繁体   English

Json4s Jackson 读写情况 class 不相等

[英]Json4s Jackson read write case class not equal

How can this be that a previously serialised and then deserialised case class is not equal:这怎么可能是先前序列化然后反序列化的情况 class 不相等:

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.好的,在尝试了一段时间后,我发现在单元测试 class 中定义一个案例 class ,它富含带有匹配器的 FlatSpec,这会以某种方式导致问题。

If defining the class outside, eg in a separate file / object, this doesn't happen.如果在外部定义 class,例如在单独的文件 / object 中,则不会发生这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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