I am using: <jackson.version>2.11.2</jackson.version>
and <scala.version>2.11.12</scala.version>
pom file:
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-scala_${scala.version.major}</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
I am having the following error:
Caused by: java.lang.ClassCastException: com.sample.ObjectName$$anon$1 cannot be cast to com.fasterxml.jackson.module.scala.ScalaObjectMapper
at com.fasterxml.jackson.module.scala.ScalaObjectMapper$class.$init$(ScalaObjectMapper.scala:338)
at com.sample.ObjectName$$anon$1.<init>(ObjectName.scala:22)
at this line(updated import statements below for more info):
import com.fasterxml.jackson.databind.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)
def toMap[V](json:String)(implicit m: Manifest[V]): Map[String, Any] = fromJson[Map[String,Any]](json)
def fromJson[T](json: String)(implicit m : Manifest[T]): T = {
mapper.readValue[T](json)
}
def toJson(value: Any): String = {
mapper.writeValueAsString(value)
}
Anyone else faced the same issue? Any suggestions for the same?