score:16
Accepted answer
I think this answer solves your question, Scala: “No manifest available for type T”. It easily solved by implicitly passing on the manifest for the type method. I add an example of the code and a simple function for error handling.
val jsonStr: String = """{"airports":[{"name":"sfo","score":1},{"name":"phx","score":1},{"name":"sjc","score":1}]}"""
case class AirPortScores(name: String, score: Double)
case class JsonRulesHandler(airports: List[AirPortScores])
val json: JsonRulesHandler = getJsonObj[JsonRulesHandler](jsonStr)
println(json)
def getJsonObj[T](jsonString:String)(implicit m: Manifest[T]): T = {
extractFrom(jsonString) match {
case Success(jsonParsed) ⇒
jsonParsed
case Failure(exc) ⇒
throw new IllegalArgumentException(exc)
}
}
private def extractFrom[T](jsonString:String)(implicit m: Manifest[T]): Try[T] = {
implicit val formats: DefaultFormats.type = DefaultFormats
Try {
parse(jsonString).extract[T]
}
}
Source: stackoverflow.com
Related Query
- Scala Dynamic Parse Json using case class No Manifest available for T
- Parse json array to a case class in scala using playframework with the fields in json not matching the fields in case class
- No TypeTag available for a case class using scala 3 with spark 3
- Generate dynamic header using Scala case class for Spark Table
- (Un)marshall JSON with named root for Ember Data using Scala case class on Spray
- Scala - No TypeTag Available Exception when using case class to try to get TypeTag?
- scala - parse json of more than 22 elements into case class
- how to parse generic case class fields using scala option parser?
- Parse a case class containing an HList into a JSON string, using Circe
- How to send Json from client with missing fields for its corresponding Case Class after using Json.format function
- Write an Arbitrary Value Not Found in a Case Class Using Play's (2.2) Scala JSON Combinators
- Scala Flink get java.lang.NoClassDefFoundError: scala/Product$class after using case class for customized DeserializationSchema
- Parse json string into scala case class in java
- Pre-persistence validation for Scala case class using Salat/Casbah
- Case Class in scala for nested JSON
- spark - mimic pyspark asDict() for scala without using case class
- Scala play api for JSON - getting Array of some case class from stringified JSON?
- Scala json object as argument for case class
- Defining Writes for case class that contains property whose type is a Map . Json / Scala / PlayFramework
- How to read optional json values in case class using scala combinators
- scala - equivalent case class for the text parsing that has dynamic number of fields
- Using case class for json validation and MongoDB persistense (Reactivemongo), what about id?
- Using Spark converting nested json with optional fields to Scala case class not working
- JsError while trying to parse JSON file into case class with Play framework API in Scala
- How to create dynamic json using for loop in scala to pass in Gatling post request
- How to parse a nested JSON available in a Hive/Hbase column using spark scala
- Annotation based Scala Json validation for Case Class
- json to case class using multiple rows in spark scala
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- How to parse JSON in Scala using standard Scala classes?
More Query from same tag
- reading 2 files at time (line by line) in scala
- Slick - Compiled with dynamic sortBy
- Using Akka ActoRef as Map key
- Scala "<-" for comprehension
- How to interpret a final tagless DSL with ZIO?
- Why does my perspective implementation fails in displaying my cube's faces?
- Filter rows based on a time stamp in another column Spark Scala
- How to retrieve Scala's version in REPL?
- Exclude libraries that are marked as Provided using the sbt-osgi plugin
- Companion Object in a List bound by the Related class' super-trait
- Unable to launch spark-shell on Spark 1.4.1b Cluster
- Make RDD from List in scala&spark
- Method in sealed trait gives Duplicate field name & signature in class file
- How to combine multiple PNGs into one big PNG file?
- Scala: Yielding from one type of collection to another
- How to serialized generic class?
- How Static allocation in spark works?
- How to parse json with a single field in Playframework2?
- Extract method to independent function in Scala
- Akka Classic Ask pattern. How does it match asks with responses?
- Why "case class" doesn't need "new" to create a new object
- Non-empty iterator over regex groups becomes empty array
- How to match a string containing double quotes?
- Functional style in Scala to collect results from a method
- General-purpose method that returns a union type
- Load a file a Lift boot?
- What is wrong with my understanding of Scala Sets?
- How to make matching schema for two data frame in join without hard coding for every columns
- Scala package delcaration - one way causes package objects visible, other makes it not?
- Parameterizing Scala Method With Parameterized Generic Class Fails