Apache Zeppelin Notebook 中的 Spray-JSON

Spray-JSON in an Apache Zeppelin Notebook

我正在使用 Zeppelin notebooksSpark Streaming 应用程序编写原型。它通过事件总线接收 JSON 小消息,我需要以(最好)分布式方式解析这些消息。我选择 spray-json 来反序列化各个消息,但我似乎无法让它工作。我认为这是因为 Zeppelin notebooks 是通过某种 REPL 接口解释的。

我直接从docs复制了这个示例:

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 的约束,但它看起来确实是一个不错的库。

多亏了@philantrovert 的评论,我才能让它工作。诀窍是将 class 和对象声明放在同一行,如下所示:

case class Color(name: String, red: Int, green: Int, blue: Int); object Color;