jackson-module-scala
jackson-module-scala copied to clipboard
[Scala Worksheet] JsonMappingException Argument of constructor has no property name annotation
One from JsonMappingException family, but most probably it is not duplicate of them, since no release fixes it.
Environment: Scala 10.4, JIdea 13.1.3 with JVM 1.7 SDK for Scala, tested with jackson module scala versions 2.2.2,2.3.2, 2.4.5, 2.5.2 with identical behaviour. The code works if run as regular Scala.
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper;
val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
case class Person(name: String, age: Int)
case class Group(name: String, persons: Seq[Person], leader: Person)
val groupJson: String = """{"name":"Scala ppl","persons":[{"name":"Jeroen","age":26},{"name":"Martin","age":54}],"leader":{"name":"Martin","age":54}}"""
val nieco: Group = mapper.readValue[Group](groupJson)
println(Group)
Worksheet results
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
mapper: com.fasterxml.jackson.databind.ObjectMapper with com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper = $anon$1@44d0b8cf
res0: com.fasterxml.jackson.databind.ObjectMapper = $anon$1@44d0b8cf
res1: com.fasterxml.jackson.databind.ObjectMapper = $anon$1@44d0b8cf
defined class Person
defined class Group
groupJson: String = {"name":"Scala ppl","persons":[{"name":"Jeroen","age":26},{"name":"Martin","age":54}],"leader":{"name":"Martin","age":54}}
com.fasterxml.jackson.databind.JsonMappingException: Argument #0 of constructor [constructor for A$A0$A$A0$Group, annotations: [null]] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2([nw] json-unmarshall-group.sc3788296715618745837.tmp:262)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer([nw] json-unmarshall-group.sc3788296715618745837.tmp:237)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer([nw] json-unmarshall-group.sc3788296715618745837.tmp:138)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer([nw] json-unmarshall-group.sc3788296715618745837.tmp:390)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer([nw] json-unmarshall-group.sc3788296715618745837.tmp:3165)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose([nw] json-unmarshall-group.sc3788296715618745837.tmp:3058)
at com.fasterxml.jackson.databind.ObjectMapper.readValue([nw] json-unmarshall-group.sc3788296715618745837.tmp:2171)
at com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper$class.readValue([nw] json-unmarshall-group.sc3788296715618745837.tmp:176)
at #worksheet#.$anon$1.readValue([nw] json-unmarshall-group.sc3788296715618745837.tmp:3)
at #worksheet#.nieco$lzycompute([nw] json-unmarshall-group.sc3788296715618745837.tmp:12)
at #worksheet#.nieco([nw] json-unmarshall-group.sc3788296715618745837.tmp:12)
at #worksheet#.#worksheet#([nw] json-unmarshall-group.sc3788296715618745837.tmp:12)
Caused by: java.lang.IllegalArgumentException: Argument #0 of constructor [constructor for A$A0$A$A0$Group, annotations: [null]] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:286)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:266)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:399)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:348)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:261)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:241)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:394)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3169)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3062)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2175)
at com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper$class.readValue(ScalaObjectMapper.scala:180)
at A$A0$A$A0$$anon$1.readValue([nw] json-unmarshall-group.sc3788296715618745837.tmp:7)
at A$A0$A$A0.nieco$lzycompute([nw] json-unmarshall-group.sc3788296715618745837.tmp:16)
at A$A0$A$A0.nieco([nw] json-unmarshall-group.sc3788296715618745837.tmp:16)
at A$A0$A$A0.get$$instance$$nieco([nw] json-unmarshall-group.sc3788296715618745837.tmp:16)
at A$A0$.main([nw] json-unmarshall-group.sc3788296715618745837.tmp:44)
at A$A0.main([nw] json-unmarshall-group.sc3788296715618745837.tmp)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Output exceeds cutoff limit.
Let me see if understand: the code works fine if you run it using scala on the command line, but not within the REPL?
Worksheet is a multiline REPL plugin so basically yes. The code works when I run it from IntelliJ, did not try to run it via command line, but I assume if compiled it will work in general.
Cool, thanks. The REPL has odd behaviors sometimes but I try and support it to the greatest extent possible. I'll take a look and see what can be done.
Sure, I raised it mainly to be in evidence. If you need any additional info o tests just let me know. Thank you.
I have similar issue. same error at least. jackson-2.5.1, scala 2.10 when start integration tests
with jackson-databind
The code like:
responseValue: Map[String, MyResponse] = mapper.readValue(expectedResponse, new TypeReference[Map[String, MyResponse]] {})
the MyResponse
@JsonTypeName(OpConstants.SUB_TYPE)
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE)
class MyResponse(coreData: CoreData, @JsonIgnore underlyingMyResponse: MyResponse) extends BasicResponse(coreData) with Serializable {
def this() = this(new CoreData, null)
... where
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE)
abstract class BasicResponse(coreData: CoreData) extends Serializable {
it works ok when I run from ide.. but got that 'constructor-error' when run from start.sh script that involves server run and go with those integration tests.
I know it may be not very concrete, but at least some info that it is still the issue.
Is there any progress on this, I'm facing similar issue. scala 2.10