Convert xml to json using scala?

I need to save xml files to Elasticsearch, for that I need to convert the xml file to json file to save it to Elasticsearch.
How can I do the job using Scala.
here is my code
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SQLContext
import org.elasticsearch.spark.sql._

object testxml {

def main(args: Array[String]): Unit = {

val conf = new SparkConf().setAppName("testxml").setMaster("local[*]")
val sc= new SparkContext(conf)
val sqlContext = new SQLContext(sc)

val df =
  .option("rowTag", "callrecord")
  .load("/home/aymenstien/Bureau/aymen/jsonfiles/VOICE CDR.xml")


val jsonfile = df.toJSON

I am getting this Error
Exception in thread “main” java.lang.NoSuchMethodError: org.apache.spark.sql.types.DecimalType$.Unlimited()Lorg/apache/spark/sql/types/DecimalType;

I’d recommend asking this question over on the Scala Users Forum instead. This one is for discussions about the language itself, and its evolution; the Users group is the place intended for usage questions. (Although I’ll also note that I suspect this is going to turn out to be a Spark question, more than a Scala question per se…)


Yeah, thank you for the answer Justin. Closing!