You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to leverage json4s for parsing the StructType from Spark.
scala> import org.apache.spark.sql.types._
scala> case class Person(name: StructType)
defined class Person
scala> import org.json4s._
import org.json4s._
scala> import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.JsonMethods._
scala> implicit val formats: Formats = DefaultFormats
scala> val json = parse(""" {"name": []} """)
scala> json.extract[Person]
org.json4s.package$MappingException: unknown error
at org.json4s.Extraction$.extract(Extraction.scala:43)
at org.json4s.ExtractableJsonAstNode.extract(ExtractableJsonAstNode.scala:21)
... 55 elided
Caused by: java.util.NoSuchElementException: head of empty list
at scala.collection.immutable.Nil$.head(List.scala:431)
at scala.collection.immutable.Nil$.head(List.scala:428)
at org.json4s.Extraction$CollectionBuilder.<init>(Extraction.scala:407)
at org.json4s.Extraction$$anonfun$extract$5.apply(Extraction.scala:382)
at org.json4s.Extraction$$anonfun$extract$5.apply(Extraction.scala:382)
at org.json4s.Extraction$.customOrElse(Extraction.scala:606)
at org.json4s.Extraction$.extract(Extraction.scala:382)
at org.json4s.Extraction$ClassInstanceBuilder.org$json4s$Extraction$ClassInstanceBuilder$$buildCtorArg(Extraction.scala:514)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$15.apply(Extraction.scala:546)
at org.json4s.Extraction$ClassInstanceBuilder$$anonfun$15.apply(Extraction.scala:546)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at org.json4s.Extraction$ClassInstanceBuilder.instantiate(Extraction.scala:546)
at org.json4s.Extraction$ClassInstanceBuilder.result(Extraction.scala:597)
at org.json4s.Extraction$$anonfun$extract$6.apply(Extraction.scala:400)
at org.json4s.Extraction$$anonfun$extract$6.apply(Extraction.scala:392)
at org.json4s.Extraction$.customOrElse(Extraction.scala:606)
at org.json4s.Extraction$.extract(Extraction.scala:392)
at org.json4s.Extraction$.extract(Extraction.scala:39)
... 56 more
StructType in Spark is actually a Spark case class with an array as parameter:
case class StructType(fields: Array[StructField]) extends DataType with Seq[StructField]
I just passed an empty list in json, I think that should work. Can any one help me fix this problem?
The text was updated successfully, but these errors were encountered:
json4s version
All versions
scala version
2.12
jdk version
java 8
I'm trying to leverage json4s for parsing the StructType from Spark.
StructType in Spark is actually a Spark case class with an array as parameter:
I just passed an empty list in json, I think that should work. Can any one help me fix this problem?
The text was updated successfully, but these errors were encountered: