Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find implicit value for evidence parameter of type org.json4s.AsJsonInput in json4s 4.0.4 #1034

Open
DrDavidS opened this issue Mar 23, 2022 · 0 comments

Comments

@DrDavidS
Copy link

json4s version

In sbt:
"org.json4s" %% "json4s-jackson" % "4.0.4"

scala version

2.12.15

jdk version

JDK8

When I learnt to use json4s to read a json file "file.json".

import org.json4s._
import org.json4s.jackson.JsonMethods._

trait DataReader {
  def readData(): List[Person]

  def readDataInefficiently(): List[Person]
}

class DataReaderImpl extends DataReader {

  implicit val formats = DefaultFormats

  private def readUntimed(): List[Person] =
    parse(StreamInput(getClass.getResourceAsStream("file.json"))).extract[List[Person]]

  override def readData(): List[Person] = readUntimed()

  override def readDataInefficiently(): List[Person] = {

    (1 to 10000).foreach(_ =>
      readUntimed())
    readUntimed()
  }
}

object DataReaderExample {
  def main(args: Array[String]): Unit = {
    val dataReader = new DataReaderImpl
    println(s"I just read the following data efficiently:${dataReader.readData()}")
    println(s"I just read the following data inefficiently:${dataReader.readDataInefficiently()}")
  }
}

It cannot compile correctly, and throw:

could not find implicit value for evidence parameter of type org.json4s.AsJsonInput[org.json4s.StreamInput]
Error occurred in an application involving default arguments.
    parse(StreamInput(getClass.getResourceAsStream("file.json"))).extract[List[Person]]

when I change json4s version in 3.6.0-M2 in sbt:

"org.json4s" %% "json4s-jackson" % "3.6.0-M2"

It gose well. Why would this happen? How should I fix it in 4.0.4?

Thank you for your Help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant