求助:scala的json4s把JValue转为对象时报错 java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$l
Posted dummyly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求助:scala的json4s把JValue转为对象时报错 java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$l相关的知识,希望对你有一定的参考价值。
测试代码:
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._
case class Winner(id: Long, numbers: List[Int])
object Test extends App{
val winner = Winner(23, List(2, 45, 34, 23, 3, 5))
//Winner转json
val json = ("id" -> winner.id) ~ ("numbers" -> winner.numbers)
//json转String
val str: String = compact(render(json))
println(str)
implicit val formats = DefaultFormats
//String转json
val jValue: JValue = parse(str)
//json转Winner
val winner2: Winner = jValue.extract[Winner]
print(winner2)
}
报错:Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$less$colon$less;
spark是1.6.1,scala是2.10.5
porm.xml
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.10</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka_2.10</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.10</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.10</artifactId>
<version>0.8.2.1</version>
</dependency>
为什么一直报错,救助!?
以上是关于求助:scala的json4s把JValue转为对象时报错 java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$l的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.ClassNotFoundException: org.json4s.JsonAST$JValue
Scala:RDD映射中的任务不可序列化由json4s“隐式val格式= DefaultFormats”引起
Why does this json4s code work in the scala repl but fail to compile?