Добавьте зависимости к вашему проекту:
libraryDependencies ++= Seq(
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % "0.45.2" % Compile,
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "0.45.2" % Provided // required only in compile-time
)
Затем определите модель, запросите фильмы, проанализируйте ответ и сохраните его в файле:
import java.nio.file._
import java.time.LocalDate
import com.github.plokhotnyuk.jsoniter_scala.macros._
import com.github.plokhotnyuk.jsoniter_scala.core._
import scala.io.BufferedSource
import scala.io.Source.fromURL
case class Movie(
vote_count: Double,
id: Double,
video: Boolean,
vote_average: Double,
title: String,
popularity: Double,
poster_path: String,
original_language: String,
original_title: String,
genre_ids: List[Double],
backdrop_path: Option[String],
adult: Boolean,
overview: String,
release_date: LocalDate)
case class Response(
page: Double,
total_results: Double,
total_pages: Double,
results: List[Movie])
implicit val codec: JsonValueCodec[Response] = JsonCodecMaker.make(CodecMakerConfig())
val parsedData = {
val source: BufferedSource = fromURL("https://api.themoviedb.org/3/search/movie?api_key=29216073ebe788cab8978c4fcbbbad23&query=Kesari")
try readFromString(source.mkString)
finally source.close()
}
Files.write(Paths.get("/tmp/movies.json"), writeToArray(parsedData))