In Json4s-jackson with Scala 2, FieldSerializer doesn't compose well with @JsonAlias, how to fix or circumvent the problem?

29 Views Asked by At

Here is a short example:

  class FieldOnly extends Sup {

    val a: String = ""

    @JsonAlias(Array("bb", "bbb")) val b: Option[Int] = None
  }

  implicit val formats: Formats = DefaultFormats + FieldSerializer[Sup]()

      import org.json4s.JsonDSL._

      {
        val jv = JObject(
          JField("a", "bc"),
          JField("bb", 3)
        )

        JsonMethods.pretty(jv)

        val mm2 = Extraction.extract[FieldOnly](jv)
        assert(mm2.a -> mm2.b == "bc" -> Some(3))
      }

This triggered the error message:

org.scalatest.exceptions.TestFailedException: ("bc", None) did not equal ("bc", Some(3))

It appears that both aliases were ignored, is there an easy fix?

0

There are 0 best solutions below