我正在使用Zeppelin notebooks为Spark Streaming应用程序编写一个原型。它通过事件总线接收小的JSON消息,我需要以(最好的)分布式方式解析这些消息。我选择了spray-json来反序列化单个消息,但我似乎无法让它正常工作。我认为这是因为Zeppelin notebooks是通过某种REPL接口来解释的。
我直接从文档复制了这个示例
case class Color(name: String, red: Int, green: Int, blue: Int)
object Color
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val colorFormat = jsonFormat4(Color.apply)
}但是它给了我以下输出:
defined class Color
defined object Color
warning: previously defined class Color is not a companion to object Color.
Companions must be defined together; you may wish to use :paste mode for this.
<console>:75: error: value apply is not a member of object Color
Note: implicit value colorFormat is not applicable here because it comes after the application point and it lacks an explicit result type
implicit val colorFormat = jsonFormat4(Color.apply)是否有另一种方法允许我在Zeppelin notebook中反序列化我的消息?我不一定要加入spray-json,但它看起来确实是一个不错的库。
发布于 2017-11-24 09:40:25
多亏了@菲兰特洛弗特的评论,我才能让它开始工作。诀窍是将类和对象声明放在同一行,如下所示:
case class Color(name: String, red: Int, green: Int, blue: Int); object Color;https://stackoverflow.com/questions/47451912
复制相似问题