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

Option serialization regression in 2.7.2 #240

Closed
akozhemiakin opened this issue Mar 5, 2016 · 6 comments
Closed

Option serialization regression in 2.7.2 #240

akozhemiakin opened this issue Mar 5, 2016 · 6 comments

Comments

@akozhemiakin
Copy link

I faced with some weird regression in 2.7.2 (in 2.6.5 all is fine).

Suppose you have this kind of data structure:

trait M
case class F(label: String) extends M
case class C(m: Option[M])

and you have some script like this:

val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)

val s = mapper.writeValueAsString(C(Some(F("foo"))))
Console.println(s)

Until you place all of this in one sbt module all will be fine. But try to place the data structure in one dependent module and the script in the other module that depends on the first one and you will get "{m:{}}" as a result of serialization (so the type information is missed).

I can create sample project showing this behavior if you wish.

@nbauernfeind
Copy link
Member

I do think that I might need a sample project to understand this issue better if you don't mind. I made changes to Option for 2.7.3 if you would also like to try the SNAPSHOT.

@jsw
Copy link

jsw commented May 21, 2016

I've run into the same issue with 2.7.3. Here's the repro repo:

https://github.com/jsw/jackson-module-scala-issue-240

@zsxwing
Copy link

zsxwing commented May 28, 2016

Not sure if this is related. I just put the following codes in the same file:

package foo

import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper

@JsonTypeInfo(
use = JsonTypeInfo.Id.CLASS,
include = JsonTypeInfo.As.PROPERTY,
property = "@class")
trait Parent

case class Child(string: String) extends Parent

case class OptionWrapper(obj: Option[Parent])

object Foo extends App {
  val mapper = new ObjectMapper() with ScalaObjectMapper {}.registerModule(DefaultScalaModule)
  val json = mapper.writeValueAsString(new OptionWrapper(Some(Child("this is a string"))))
  println(json)
}

For 2.7.3, it outputs {"obj":{"@class":"foo.Child"}}, which is incorrect. The string field of Child is not in the json.

For 2.6.5, it outputs the correct result: {"obj":{"@class":"foo.Child","string":"this is a string"}}.

@jsw
Copy link

jsw commented Jun 28, 2016

@nbauernfeind Any comment on this issue? I provided a bare bones repro repo above.

@arpadtamasi
Copy link

I face the same in 2.7.4

@poroszd
Copy link

poroszd commented Jul 7, 2016

@brharrington's fix #271 works for me.

Anyway, I found that:

  • if the trait is not in an object, serialization is broken
  • if the trait is in an object and typed with @JsonType, serialization is broken
  • if the trait is in an object, serialization works.

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

No branches or pull requests

6 participants