使用grater.fromJson忽略JSON中的额外数据

时间:2014-10-28 02:20:40

标签: mongodb scala casbah salat

我正在尝试使用salat将一些JSON文档导入到我的case类模型中。基本上,我这样做;

grater[RootModel].fromJSON(json)

我已经为我关心的数据实现了案例类层次结构,但是我回来的JSON文档通常具有我不关心的额外值。当我运行上面的操作时,我会收到类似下面的错误。有没有办法配置salat来忽略那些我不关心的额外值?

[error] (run-main-3) java.lang.Exception: class RootModel requires value for 'bogusField'
java.lang.Exception: class RootModel requires value for 'bogusField'
    at com.novus.salat.DefaultArg.safeValue$lzycompute(Grater.scala:462)
    at com.novus.salat.DefaultArg.safeValue(Grater.scala:458)
    at com.novus.salat.ConcreteGrater.safeDefault(Grater.scala:419)
    at com.novus.salat.ConcreteGrater$$anonfun$8$$anonfun$apply$5.apply(Grater.scala:377)
    at com.novus.salat.ConcreteGrater$$anonfun$8$$anonfun$apply$5.apply(Grater.scala:377)
    at scala.Option.orElse(Option.scala:266)
    at com.novus.salat.ConcreteGrater$$anonfun$8.apply(Grater.scala:377)
    at com.novus.salat.ConcreteGrater$$anonfun$8.apply(Grater.scala:360)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.immutable.List.map(List.scala:284)
    at com.novus.salat.ConcreteGrater.fromJSON(Grater.scala:360)
    at com.novus.salat.Grater.fromJSON(Grater.scala:73)
    at User$.createCaseClass(hello.scala:20)
    at Hello$.main(hello.scala:27)
    at Hello.main(hello.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)

0 个答案:

没有答案