1

I am trying to use salat to import some JSON documents into my case class model. Basically, I'm doing this;

grater[RootModel].fromJSON(json)

I have implemented the case class hierarchy for the data I care about, but the JSON doc I get back often has extra values I don't care about. When I run the above, I get errors like the one below. Is there any way to configure salat to just ignore those extra values I don't care about?

[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)
XeroxDucati
  • 5,130
  • 2
  • 37
  • 66
  • `class RootModel requires value for 'bogusField'` implies that the JSON string is missing a field required by `RootModel`, rather than having extra fields you don't need. Can you please provide a sample case class and JSON data to illustrate the problem you're having? – noahlz Mar 20 '15 at 05:24

0 Answers0