4

这是我正在使用的导入:

import com.novus.salat._
import com.novus.salat.global.ctx
import net.liftweb.json._
import com.mongodb.casbah.Imports._

我有两个案例类:

case class BigThing (thing: Thing  )
case class Thing(x:Int, y:Int)

我的刨丝器在单独刨丝时正确地生成了一个带有字段名称的 DBObject:

implicit val formats = DefaultFormats

val t = parse("""{"x":5, "y":6}""").extract[Thing]
println("t " + t)
val dboT = grater[Thing].asDBObject(t)
println("dboT " + dboT)

这打印:

 t Thing(5,6)
 dboT { "_typeHint" : "Thing" , "x" : 5 , "y" : 6}

但是当对 BigThing 进行光栅化时,Thing 的字段名称会变成一个数组:

  val bt = parse(""" { "thing": {"x":5, "y":6} } """).extract[BigThing]
  println("bt " + bt)
  val dboBt = grater[BigThing].asDBObject(bt)
  println("dboBt " + dboBt)

这打印:

bt BigThing(Thing(5,6))
dboBt { "_typeHint" : "BigThing" , "thing" : [ 5 , 6]}

这是一个错误吗?我做错了什么?


我的 build.sbt 字段是这样的:

name := "hello"

resolvers ++= Seq(
  "ScalaNLP Maven2" at "http://repo.scalanlp.org/repo",
  "Spray repo" at "http://repo.spray.cc/",
  "Typesafe repo" at "http://repo.typesafe.com/typesafe/releases/",
  "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")

libraryDependencies ++= Seq(
  "com.novus"                  %% "salat-core"      % "1.9.1-SNAPSHOT",
  "cc.spray"                   %% "spray-json"      % "1.1.1",
  "com.mongodb.casbah"         %  "casbah_2.9.1"    % "2.1.5-1",
  "net.liftweb"                %% "lift-json"       % "2.5-SNAPSHOT"
)
4

0 回答 0