json4s / json4s

JSON library
http://json4s.org
Apache License 2.0
1.48k stars 328 forks source link

extraction always yield empty JObject if loaded AFTER scalatest 3.2.10 #1082

Open tribbloid opened 2 years ago

tribbloid commented 2 years ago

(Original post:)

https://stackoverflow.com/questions/72587978/in-json4s-why-does-the-extract-function-always-yield-empty-object-result

Here is a simple example:

  implicit val formats: Formats = DefaultFormats

  case class StrInt(
      a: String = "A",
      b: Int = 2
  )

    val d1 = StrInt("a", 12)
    val json = decompose(d1)

    println(json)

The result of the above code is JObject(Nil). Instead off a JObject with 2 fields.

It was discovered when migrating my tests from maven to gradle, of which classloader loads test dependency before main jars. Thus producing the above result. Otherwise the problem won't manifest

json4s version

3.5.5

scala version

2.12.16

jdk version

OpenJDK 1.8

tribbloid commented 2 years ago

same bug encountered on v3.6.12