Все, что мне нужно для выполнения базового кода библиотеки Джексона с использованием scala в редакторе Intellij Idea
Я уже установил scala C: \ Users \ tt> scala -version Scala runner code 2.12.7 - Авторские права2002-2018, LAMP / EPFL и Lightbend, Inc.
import com.fasterxml.jackson.databind.ObjectMapper
import scala.collection.mutable
val input = scala.io.Source.fromFile("data.json").getLines()
val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.registerModule(DefaultScalaModule)
val obj = mapper.readValue[Map[String, Any]](input)
val data_collection = mutable.HashMap.empty[Int, String]
for (i <- c) {
data_collection.put(
obj.get("id").fold(0)(_.toString.toInt),
obj.get("text").fold("")(_.toString)
)
}
println(data_collection) // Map(1 -> Hello How are you)
Я ожидаю, что редактор IntelliJ автоматически предложит, почему ScalaObjectMapper и DefaultScalaModule отображаются как символы Cannot Resolve, несмотря на использование правильных импортов
Получение ошибоккак показано ниже
Error:(4, 1) expected class or object definition
name := "jackson-module-scala"
Error:(6, 1) expected class or object definition
organization := "com.fasterxml.jackson.module"
Error:(8, 1) expected class or object definition
scalaVersion := "2.12.8"
Error:(10, 1) expected class or object definition
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.8",
"2.13.0-M5")
Error:(12, 1) expected class or object definition
val scalaMajorVersion = SettingKey[Int]("scalaMajorVersion")
Error:(13, 1) expected class or object definition
scalaMajorVersion := {
Error:(20, 1) expected class or object definition
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature")
Error:(27, 6) classes cannot be lazy
lazy val java7Home =
Error:(33, 1) expected class or object definition
javacOptions ++= {
Error:(41, 1) expected class or object definition
scalacOptions ++= {
Error:(45, 1) expected class or object definition
unmanagedSourceDirectories in Compile += {
Error:(49, 1) expected class or object definition
val jacksonVersion = "2.9.8"
Error:(51, 1) expected class or object definition
libraryDependencies ++= Seq(
Error:(65, 1) expected class or object definition
resourceGenerators in Compile += Def.task {
Error:(73, 1) expected class or object definition
site.settings
Error:(75, 1) expected class or object definition
site.includeScaladoc()
Error:(77, 1) expected class or object definition
ghpages.settings
Error:(79, 1) expected class or object definition
git.remoteRepo := "git@github.com:FasterXML/jackson-module-
scala.git"