Felix.Reuthlinger
Felix.Reuthlinger

Reputation: 93

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)

Upvotes: 1

Views: 180

Answers (1)

Felix.Reuthlinger
Felix.Reuthlinger

Reputation: 93

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, e.g. in a separate file / object, this doesn't happen.

Upvotes: 3

Related Questions