Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Json4s-jackson with Scala 2, FieldSerializer doesn't compose well with @JsonAlias #1427

Open
tribbloid opened this issue Feb 16, 2024 · 0 comments

Comments

@tribbloid
Copy link

json4s version

3.7.0-M11

scala version

2.13.12

jdk version

11

(main article: https://stackoverflow.com/questions/77970715/in-json4s-jackson-with-scala-2-fieldserializer-doesnt-compose-well-with-jsona)

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant