Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Serialization of Enumeration bug? #66

Closed
slorber opened this Issue · 11 comments

2 participants

@slorber

Hello,

I have posted the problem on StackOverflow:
http://stackoverflow.com/questions/15887785/jackson-scala-module-serialize

Any idea?

@slorber

Does your recent changes on Enumeration (@JsonScalaEnumeration(classOf[WeekdayType])) fixes this problem?

@christophercurrie

Not specifically; the recent changes on the master branch are targeting version 2.2, yet to be released. The bug report is on the 2.1 version, and I've not yet been able to reproduce your specific issue.

If you'd like to try the latest 2.2 version, I've made them available on the Sonatype OSS Snapshots repository: https://oss.sonatype.org/index.html#nexus-search;gav~com.fasterxml.jackson.*~~2.2.0-SNAPSHOT~~

@slorber

One important thing I didn't notice at first is that the 2 classes on my SO question: SimpleCaseClass / SimpleCaseClassWithEnum.
They are in my test method local case classes!

I upgraded to 2.2.0 and the serialization of these classes which used to work now produces an empty string {}.

By moving them outside the method I get an exception:

Caused by: java.lang.NullPointerException: null
    at com.fasterxml.jackson.module.scala.introspect.ScalaClassIntrospector$.isMaybeScalaBeanType(ScalaClassIntrospector.scala:15) ~[jackson-module-scala_2.10-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]
    at com.fasterxml.jackson.module.scala.introspect.ScalaClassIntrospector$.constructPropertyCollector(ScalaClassIntrospector.scala:28) ~[jackson-module-scala_2.10-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]
    at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.collectProperties(BasicClassIntrospector.java:142) ~[jackson-databind-2.2.0-SNAPSHOT.jar:2.2.0-SNAPSHOT]
@slorber

By the way, the 3rd test with my real case class Relationship (not method local), it now works as expected, with or without the annotation.

By the way, another important thing to mention because I took a look at ScalaClassIntrospector sources: my method local case classes moved outside the method didn't have any package!

@slorber

So in the end my bug seems to be fixed and the new annotation seems to work fine.

But:

  • There is a NPE for case classes with no package
  • Since 2.2.0 we can't serialize inner case classes (in object or method) anymore, it produces empty json object

Thanks for fixing this quickly.

By the way, I don't really understand the Jackson world, why are there 2 packages (codehale vs fasterxml?).
And what is your position compared to Jerkson? Jerkson seems abandonned, is your project some kind of "continuation" of Jerkson?

@christophercurrie

Thanks for the bug report on case classes with no package, I'll look into that. Inner case classes have never been fully supported, though there were edge cases where they may have worked. It's something I would like to solve generally in a future release.

I'm not aware of any 'codahale' packages for Jackson other than Jerkson. Jerkson was Coda's extension of Jackson for Scala, developed independently of this module. Since Yammer is moving away from Scala as an implementation language, Coda's Scala related work is being deprecated in favor of other alternatives.

I will open new issues to track the NPE and inner case class problems you reported.

@slorber

Ok thanks. I didn't know Jerkson was from Yammer and I though Codahale was an organisation releasing Jackson... (was confused because of Codahale / Codehaus)

@slorber

By the way one of our developers had this error:

[RuntimeException: java.lang.UnsupportedClassVersionError: com/fasterxml/jackson/module/scala/JsonScalaEnumeration : Unsupported major.minor version 51.0]

I guess it's because he's using an old JRE while you compiled the library with JDK7.
Perhaps you should compile it with -target 1.6 or something so that it is compatible with more JRE

@slorber

By the way, she didn't have this error before this change:

  • "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.2.0-SNAPSHOT",
  • "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.2.0",

So I guess the snapshot was compatible with JDK6 while the official release is not :)

@christophercurrie

Yes, this was clearly a bad build created on my end. I'll look into what it takes to get a replacement build out ASAP. I'm hopeful I'll be able to retain the same version number, but I don't know if the Maven ecosystem will let me do that.

@christophercurrie

I've staged a potential replacement version on the Sonatype OSS Maven repository. You can download the 2.2.1 version for your either directly from the repository website, or by adding a reference to the repository to your build (instructions below). Let me know if you have a chance and can validate that this new build works for you.

<!-- For maven
<repository>
  <id>comfasterxml-046</id>
  <name>Fasterxml Staging</name>
  <releases><enabled>true</enabled></releases>
  <snapshots><enabled>false</enabled></snapshots>
  <url>https://oss.sonatype.org/content/repositories/comfasterxml-046/</url>
</repository>
// For sbt
resolvers += "Fasterxml Staging" at "https://oss.sonatype.org/content/repositories/comfasterxml-046/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.