【发布时间】:2017-11-23 09:29:40
【问题描述】:
我正在使用Zeppelin notebooks 为Spark 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 的约束,但它看起来确实是一个不错的库。
【问题讨论】:
-
Scala REPL 有一个粘贴模式。不确定 Zeppelin 中是否可用。你可以试试
case class Color(name: String, red: Int, green: Int, blue: Int); object Color; -
issues.apache.org/jira/browse/ZEPPELIN-658 你也可以在你的解释器中试试
:paste吗? -
这也是 scala-repl 的问题。这个@philantrovert有一个骗局,我不知道它现在在哪里:/
-
:paste不起作用,我应该提到我已经尝试过了。 @philantrovert 提供的解决方案效果很好,谢谢!
标签: scala apache-spark spray apache-zeppelin spray-json