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

Fields defined in scala object and trait are not serialized #495

Closed
yufangong opened this issue Jan 19, 2021 · 6 comments
Closed

Fields defined in scala object and trait are not serialized #495

yufangong opened this issue Jan 19, 2021 · 6 comments
Labels

Comments

@yufangong
Copy link

In the process of bumping Jackson version from 2.11.2 to 2.12.0, we have noticed this behavior change:

trait TraitWithoutJsonProperty {
  val name = "name1"
}
object ObjectWithoutJsonProperty extends TraitWithoutJsonProperty {
  val value = "value1"
}

This ObjectWithoutJsonProperty on 2.11.2 will be serialized with fields value, but not on 2.12.0.

2.11.2 output: {"value":"value1","name":"name1"}
2.12.0 output: {}

We also find out that adding @JsonProperty annotation can write the fields, however, it can be hard for us to detect our customer's usage.

The full reproduce example is located here.
Thank you!

@pjfanning
Copy link
Member

I added a test case to 2.11 branch and it passes but it does fail in 2.12. I have marked it as ignored in 2.12 branch while it is investigated.

@pjfanning
Copy link
Member

One workaround is to make the object a 'case object' - that seems to work.

Some changes were made in v2.12.0 to try to avoid having jackson-module-scala affect non-Scala classes. It looks like Scala objects that are not case objects are not recognised as being Scala classes.

@yufangong
Copy link
Author

Thanks for the quick response @pjfanning.
Unfortunately, it doesn't seem we can patch all users for the workaround so we may need to wait until a fix. If anything we can help with here, please let us know.

Another note is we noticed ScalaObjectMapper is deprecated without replacement in 2.12.X, what's the future plan for it?

@pjfanning
Copy link
Member

No plans for ScalaObjectMapper - it will not work in Scala 3. There may eventually be a replacement that uses Scala 3 friendly TypeTags or something similar.

@pjfanning
Copy link
Member

will be released in v2.12.2

@pjfanning
Copy link
Member

pjfanning commented Jan 19, 2021

@yufangong the test case I added in jackson v2.11 branch works with Scala 2.10, 2.11 and 2.12 but fails with Scala 2.13.
-- see https://travis-ci.com/github/FasterXML/jackson-module-scala/builds/213704601

With this jackson v2.12, the test case passes with all supported Scala versions (Scala 2.10 support has been dropped)

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

No branches or pull requests

2 participants