{"action":"created","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-module-scala/issues/246","repository_url":"https://api.github.com/repos/FasterXML/jackson-module-scala","labels_url":"https://api.github.com/repos/FasterXML/jackson-module-scala/issues/246/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-module-scala/issues/246/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-module-scala/issues/246/events","html_url":"https://github.com/FasterXML/jackson-module-scala/issues/246","id":146072170,"number":246,"title":"NPE when deserializing","user":{"login":"raviv","id":145637,"avatar_url":"https://avatars.githubusercontent.com/u/145637?v=3","gravatar_id":"","url":"https://api.github.com/users/raviv","html_url":"https://github.com/raviv","followers_url":"https://api.github.com/users/raviv/followers","following_url":"https://api.github.com/users/raviv/following{/other_user}","gists_url":"https://api.github.com/users/raviv/gists{/gist_id}","starred_url":"https://api.github.com/users/raviv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raviv/subscriptions","organizations_url":"https://api.github.com/users/raviv/orgs","repos_url":"https://api.github.com/users/raviv/repos","events_url":"https://api.github.com/users/raviv/events{/privacy}","received_events_url":"https://api.github.com/users/raviv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-05T18:32:54Z","updated_at":"2016-04-05T21:08:58Z","closed_at":null,"body":"Hi,\r\n\r\nI'm using the following versions:\r\njackson-core  2.7.3\r\njackson-databind 2.7.3\r\njackson-module-scala 2.7.2\r\n\r\nand getting the above error when deserializing a case class as follows:\r\n\r\n\r\n```\r\n    case class FooClass (bar:String)\r\n\r\n    val mapper = new ObjectMapper() with ScalaObjectMapper\r\n    mapper.registerModule(DefaultScalaModule)\r\n\r\n    var foo = FooClass(\"hello\")\r\n\r\n    val jsonString = mapper.writeValueAsString(foo)\r\n    println(jsonString) // works fine\r\n    foo = mapper.readValue[FooClass](jsonString) // getting exception\r\n\r\n    foo.bar should be (\"hello\")\r\n```\r\n\r\nHere is the stack trace:\r\n\r\n```\r\nInstantiation of [simple type, class com.origami.common.JsonTests$$anonfun$1$FooClass$3] value failed (java.lang.NullPointerException): null\r\n at [Source: {\"bar\":\"hello\"}; line: 1, column: 15]\r\ncom.fasterxml.jackson.databind.JsonMappingException: Instantiation of [simple type, class com.origami.common.JsonTests$$anonfun$1$FooClass$3] value failed (java.lang.NullPointerException): null\r\n at [Source: {\"bar\":\"hello\"}; line: 1, column: 15]\r\n\tat com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:223)\r\n\tat com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.wrapAsJsonMappingException(StdValueInstantiator.java:445)\r\n\tat com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.rewrapCtorProblem(StdValueInstantiator.java:464)\r\n\tat com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:258)\r\n\tat com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:135)\r\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:444)\r\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1123)\r\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:298)\r\n\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:133)\r\n\tat com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)\r\n\tat com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2817)\r\n\tat com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper$class.readValue(ScalaObjectMapper.scala:184)\r\n\tat com.origami.common.JsonTests$$anonfun$1$$anon$1.readValue(JsonTests.scala:33)\r\n\tat com.origami.common.JsonTests$$anonfun$1.apply$mcV$sp(JsonTests.scala:40)\r\n\tat com.origami.common.JsonTests$$anonfun$1.apply(JsonTests.scala:29)\r\n\tat com.origami.common.JsonTests$$anonfun$1.apply(JsonTests.scala:29)\r\n\tat org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22)\r\n\tat org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)\r\n\tat org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)\r\n\tat org.scalatest.Transformer.apply(Transformer.scala:22)\r\n\tat org.scalatest.Transformer.apply(Transformer.scala:20)\r\n\tat org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1647)\r\n\tat org.scalatest.Suite$class.withFixture(Suite.scala:1122)\r\n\tat org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1683)\r\n\tat org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1644)\r\n\tat org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1656)\r\n\tat org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1656)\r\n\tat org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)\r\n\tat org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1656)\r\n\tat org.scalatest.FlatSpec.runTest(FlatSpec.scala:1683)\r\n\tat org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1714)\r\n\tat org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1714)\r\n\tat org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:413)\r\n\tat org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:401)\r\n\tat scala.collection.immutable.List.foreach(List.scala:318)\r\n\tat org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)\r\n\tat org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:390)\r\n\tat org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:427)\r\n\tat org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:401)\r\n\tat scala.collection.immutable.List.foreach(List.scala:318)\r\n\tat org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)\r\n\tat org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:396)\r\n\tat org.scalatest.SuperEngine.runTestsImpl(Engine.scala:483)\r\n\tat org.scalatest.FlatSpecLike$class.runTests(FlatSpecLike.scala:1714)\r\n\tat org.scalatest.FlatSpec.runTests(FlatSpec.scala:1683)\r\n\tat org.scalatest.Suite$class.run(Suite.scala:1424)\r\n\tat org.scalatest.FlatSpec.org$scalatest$FlatSpecLike$$super$run(FlatSpec.scala:1683)\r\n\tat org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1760)\r\n\tat org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1760)\r\n\tat org.scalatest.SuperEngine.runImpl(Engine.scala:545)\r\n\tat org.scalatest.FlatSpecLike$class.run(FlatSpecLike.scala:1760)\r\n\tat org.scalatest.FlatSpec.run(FlatSpec.scala:1683)\r\n\tat org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:55)\r\n\tat org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2563)\r\n\tat org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2557)\r\n\tat scala.collection.immutable.List.foreach(List.scala:318)\r\n\tat org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2557)\r\n\tat org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1044)\r\n\tat org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1043)\r\n\tat org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2722)\r\n\tat org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)\r\n\tat org.scalatest.tools.Runner$.run(Runner.scala:883)\r\n\tat org.scalatest.tools.Runner.run(Runner.scala)\r\n\tat org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:138)\r\n\tat org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)\r\nCaused by: java.lang.NullPointerException\r\n\tat com.origami.common.JsonTests$$anonfun$1$FooClass$3.<init>(JsonTests.scala:31)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\r\n\tat com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:114)\r\n\tat com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:256)\r\n\t... 61 more\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/FasterXML/jackson-module-scala/issues/comments/205985185","html_url":"https://github.com/FasterXML/jackson-module-scala/issues/246#issuecomment-205985185","issue_url":"https://api.github.com/repos/FasterXML/jackson-module-scala/issues/246","id":205985185,"user":{"login":"raviv","id":145637,"avatar_url":"https://avatars.githubusercontent.com/u/145637?v=3","gravatar_id":"","url":"https://api.github.com/users/raviv","html_url":"https://github.com/raviv","followers_url":"https://api.github.com/users/raviv/followers","following_url":"https://api.github.com/users/raviv/following{/other_user}","gists_url":"https://api.github.com/users/raviv/gists{/gist_id}","starred_url":"https://api.github.com/users/raviv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raviv/subscriptions","organizations_url":"https://api.github.com/users/raviv/orgs","repos_url":"https://api.github.com/users/raviv/repos","events_url":"https://api.github.com/users/raviv/events{/privacy}","received_events_url":"https://api.github.com/users/raviv/received_events","type":"User","site_admin":false},"created_at":"2016-04-05T21:08:58Z","updated_at":"2016-04-05T21:08:58Z","body":"Update: Turns out the code above is failing only when ran inside a scala test. \r\nSo this fails\r\n```\r\nclass JsonTests extends FlatSpec  {\r\n\r\n  \"Case class\" should \"serialize and deserialize\" in {\r\n\r\n    class FooClass (val bar:String)  {\r\n      var baz:Option[String] = None\r\n    }\r\n\r\n    val mapper = new ObjectMapper() with ScalaObjectMapper\r\n    mapper.registerModule(DefaultScalaModule)\r\n\r\n    val foo = new FooClass(\"hello\")\r\n    foo.baz = Some(\"world\")\r\n\r\n    val JsonIn = mapper.writeValueAsString(foo)\r\n    println(JsonIn)\r\n\r\n    val fooCopy = mapper.readValue[FooClass](JsonIn)\r\n    assert(fooCopy.baz.get ==\"world\")\r\n\r\n    val jsonOut = mapper.writeValueAsString(fooCopy)\r\n    println(jsonOut)\r\n  }\r\n}\r\n```\r\n\r\nWhile this works:\r\n```\r\nobject Example extends App{\r\n\r\n  class FooClass (val bar:String)  {\r\n    var baz:Option[String] = None\r\n  }\r\n\r\n  val mapper = new ObjectMapper() with ScalaObjectMapper\r\n  mapper.registerModule(DefaultScalaModule)\r\n\r\n  val foo = new FooClass(\"hello\")\r\n  foo.baz = Some(\"world\")\r\n\r\n  val JsonIn = mapper.writeValueAsString(foo)\r\n  println(JsonIn)\r\n\r\n  val fooCopy = mapper.readValue[FooClass](JsonIn)\r\n  assert(fooCopy.baz.get ==\"world\")\r\n\r\n  val jsonOut = mapper.writeValueAsString(fooCopy)\r\n  println(jsonOut)\r\n\r\n}\r\n```\r\n"}}