NoSuchMethodError при попытке сгенерировать строки JSON из карты Scala с использованием Lift-JSON

Получение NoSuchMethodError при попытке сгенерировать строки JSON из карты Scala с помощью Lift-JSON . Пытался выполнить следующую программу из поваренной книги scala

    package com.sample


import net.liftweb.json.JsonAST
import net.liftweb.json.JsonDSL._
import net.liftweb.json.Printer.{compact,pretty}

object LiftJsonWithCollections extends App {  
  val json = List(1, 2, 3) 
  println(compact(JsonAST.render(json)))  
  val map = Map("fname" -> "Alvin", "lname" -> "Alexander") 
  println(compact(JsonAST.render(map)))
}

Я получаю следующую ошибку

Exception in thread "main" java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
    at net.liftweb.json.Printer$class.layout$1(JsonAST.scala:597)
    at net.liftweb.json.Printer$class.compact(JsonAST.scala:605)
    at net.liftweb.json.Printer$.compact(JsonAST.scala:583)
    at net.liftweb.json.Printer$class.compact(JsonAST.scala:590)
    at net.liftweb.json.Printer$.compact(JsonAST.scala:583)
    at com.sample.LiftJsonWithCollections$.delayedEndpoint$com$sample$LiftJsonWithCollections$1(LiftJsonWIthCollection.scala:10)
    at com.sample.LiftJsonWithCollections$delayedInit$body.apply(LiftJsonWIthCollection.scala:8)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at com.sample.LiftJsonWithCollections$.main(LiftJsonWIthCollection.scala:8)
    at com.sample.LiftJsonWithCollections.main(LiftJsonWIthCollection.scala)

Не могу решить.

Я добавил следующую зависимость в pom

<dependency>
            <groupId>net.liftweb</groupId>
            <artifactId>lift-json_2.11</artifactId>
            <version>3.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.json4s/json4s-jackson -->
        <dependency>
            <groupId>org.json4s</groupId>
            <artifactId>json4s-jackson_2.11</artifactId>
            <version>3.2.10</version>
        </dependency>

person Community    schedule 01.09.2018    source источник


Ответы (1)


Когда я удалил метод JsonAST и написал следующий код, он работает.

object LiftJsonWithCollections extends App { 
  implicit val formats = DefaultFormats
  val json = List(1, 2, 3) 
  **println(compact(render(json)))**  
  val map = Map("fname" -> "Alvin", "lname" -> "Alexander") 
  **println(compact(render(map)))**
}

Однако я также могу найти метод рендеринга в JsonAST API. Как это работает ?

person Community    schedule 02.09.2018