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

(Regression) JsonMappingException Argument of constructor has no property name annotation #102

Closed
ittaiz opened this issue Oct 9, 2013 · 3 comments

Comments

@ittaiz
Copy link

ittaiz commented Oct 9, 2013

The following code breaks on scala module 2.2.3 but works fine on 2.2.2:

case class WorksWithOtherValMember(@reflect.BeanProperty property: String = "",
                              @reflect.BeanProperty otherProperty: String = ""){
}
case class WorksWithoutOtherMember(@reflect.BeanProperty property: String = ""){
}
case class BrokenWithVarOtherMember(@reflect.BeanProperty property: String = "",
                              @reflect.BeanProperty var otherProperty: String){
}

val om = new com.fasterxml.jackson.databind.ObjectMapper
om.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule)
om.readValue("""{"property": ""}""",classOf[WorksWithOtherValMember])
om.readValue("""{"property": ""}""",classOf[WorksWithoutOtherMember])
om.readValue("""{"property": ""}""",classOf[BrokenWithVarOtherMember])

I'm not really sure why it breaks but it does; I'm guessing something in this module changed in handling the var ctor members of case classes.
This might be related to #29 since the error message is the same.
The above example is the most minified version of it I could create. Our code breaks in a similar fashion.
The output from the console is:

     |      | defined class WorksWithOtherValMember

scala>      | defined class WorksWithoutOtherMember

scala>      |      | defined class BrokenWithVarOtherMember

scala> om: com.fasterxml.jackson.databind.ObjectMapper = com.fasterxml.jackson.databind.ObjectMapper@2d35eea7

scala> res0: com.fasterxml.jackson.databind.ObjectMapper = com.fasterxml.jackson.databind.ObjectMapper@2d35eea7

scala> res1: WorksWithOtherValMember = WorksWithOtherValMember(,null)

scala> res2: WorksWithoutOtherMember = WorksWithoutOtherMember()

scala> com.fasterxml.jackson.databind.JsonMappingException: Argument #1 of constructor [constructor for BrokenWithVarOtherMember, annotations: [null]] has no property name annotation; must have name when multiple-paramater constructor annotated as Creator
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:272)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:247)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:146)
    at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:322)
    at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:2990)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2884)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
    at .<init>(<console>:11)
    at .<clinit>(<console>)
    at .<init>(<console>:7)
    at .<clinit>(<console>)
    at $print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
    at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
    at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
    at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745)
    at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790)
    at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702)
    at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566)
    at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573)
    at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
    at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
    at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
    at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
    at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:889)
    at org.jetbrains.plugins.scala.compiler.rt.ConsoleRunner.main(ConsoleRunner.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.IllegalArgumentException: Argument #1 of constructor [constructor for BrokenWithVarOtherMember, annotations: [null]] has no property name annotation; must have name when multiple-paramater constructor annotated as Creator
    at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:283)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:263)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:405)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:354)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:267)
    ... 38 more

@christophercurrie
Copy link
Member

Thanks for the report. I'll look into this as soon as I can.

@christophercurrie
Copy link
Member

This looks to be a duplicate of #101; the test above is currently succeeding on master, and the fix will go out in Jackson 2.3.

@christophercurrie
Copy link
Member

Version 2.3.0-rc1 has been released with this fix. It'd be a big help if you could try out the release candidate and let us know if you have any issues.

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

2 participants