我尝试使用以下代码解析jsons:
import java.text.SimpleDateFormat
import org.json4s._
import org.json4s.ext.EnumNameSerializer
import org.json4s.native.JsonMethods._
object Area extends Enumeration {
type Area = Value
val grid, stream = Value
}
implicit val formats = new DefaultFormats {
override def dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
} + new EnumNameSerializer(Area)
case class EventJsonInput(ids: Array[String]
, cluster: Int
, operation: String
, area: Area.Area
, position: Option[Int]
)
parse("""{"ids":["1"],"operation": "update","cluster": 3,
"area": "grid"} """).extractOpt[EventJsonInput]
当我通过sbt运行时 - >控制台我得到以下结果:
res0: Option[EventJsonInput] = Some(EventJsonInput([Ljava.lang.String;@29f999f,3,update,grid,None))
当我在工作表中通过交互模式运行它时,结果是:
res0: Option[EventJsonInput] = None
我不明白为什么:(我试图让Everythin成为可选项,但它并没有帮助。
sbt - >约:
[info] This is sbt 0.13.8
[info] The current project is {file:/home/user/.../}... 0.025-SNAPSHOT
[info] The current project is built against Scala 2.10.5
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbtassembly.AssemblyPlugin, sbtdocker.DockerPlugin, sbtrelease.ReleasePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4