score:9
From your compile error, it looks like jsonFormat2
expects a two-argument function. Do you mean to pass the constructors of Foo
and Bar
into it? If so, you should do Foo.apply
and Bar.apply
.
score:1
Spray.json documentation suggests an easier way than @wingedsubmariner's suggestion:
If you explicitly declare the companion object for your case class the notation above will stop working. You'll have to explicitly refer to the companion object's
apply
method to fix this:
So the correction for the question becomes:
implicit val fooFormat = jsonFormat2(Foo.apply)
Added: This is in fact what also @geoffliu suggests in his answer.
score:4
Case class companion objects will by default extend one of the function traits. object Foo
would have extended ((String, List[String]) => Foo)
but when you manually defined it you didn't extend that trait. This is why you couldn't pass it to jsonFormat2
, which was expecting a (?, ?) => ?
. If you make the following change your code should compile:
object Foo extends ((String, List[String]) => Foo) {
Source: stackoverflow.com
Related Query
- Compile error when using a companion object of a case class as a type parameter
- Case class companion object generation error for compound type
- Access companion object from case class (or vice-versa) using scala type macros
- No RowReaderFactory can be found for this type error when trying to map Cassandra row to case object using spark-cassandra-connector
- Understanding type arguments do not conform to class type parameter bounds error when using Higher kinded type parameter
- Using .tupled method when companion object is in class
- Why is the error "Unable to find encoder for type stored in a Dataset" when encoding JSON using case classes?
- generic trait taking a class and it's companion object as a type parameter
- Type Parameter in Case Class Using Trait w/ Implicits
- Type error when using a type parameter as a type argument for another type being passed to a macro implementation
- Type mismatch when utilising a case class in a package object
- StackOverflowError When Calling RDD#toDS Using Java Object Instead of a Scala Case Class
- Why do I get a type mismatch error when using a UDF that returns an object of type Option[Long]?
- Scala preserve type parameter of case class object upon copying
- Passing TableQuery object as a parameter results in strange type error in Slick/Scala but not when injected
- Type mismatch when using Scala case class constructor as a method call
- what is the data type of object when passing to another class in scala ? or how to pass an object type as a parameter to another class?
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- Get companion object of class by given generic type Scala
- Scala - No TypeTag Available Exception when using case class to try to get TypeTag?
- Scala compile server error when using nailgun
- Scala: order of definition for companion object vs case class
- Compiler error about class graph being not finitary due to a expansively recursive type parameter
- Spark case class - decimal type encoder error "Cannot up cast from decimal"
- Why do I get "expected class or object definition" when defining a type in scala?
- How to get the name of a case class field as a string/symbol at compile time using shapeless?
- Case class and companion object
- How do I create an explicit companion object for a case class which behaves identically to the replaced compiler provided implicit companion object?
- Tupled method for case class having a type parameter
- Scala dependency injection when using case class/companion object pattern
More Query from same tag
- Scala case class instantiate when you have not-used-in-equals properties
- Can I get a compile-time list of all of the case objects which derive from a sealed parent in Scala?
- scalajs-react : Unexpected difference in Ajax GET vs DELETE
- Manual JAR compilation for Scala & Kotlin
- Scala: Prepending an Underscore to Function Name
- Distribute the value of a Spark Dataframe row proportionately to other rows
- How to get the posted "id=1&id=2" in action, in play2?
- Read file path available in a dataframe and read content of those files using spark
- js.Function2, how to?
- Play framework stops immediately after starded
- How can I implement a monadic interface (map, flatMap) for a type R[Out] { type In }?
- Extract list to multiple distinct list
- Spark Kafka Consumer not consuming messages from topic
- Running a Java-based Spark Job on spark-jobserver
- Scala: Take List[People] and Convert it to a Map[String, List[People]]
- Couldn't run ensime on Play 2.3 project
- Why is the Scala for-loop (and internals) NumericRange restricted to Int size and how to elaborate the functionality?
- Running Scala module with databricks-connect
- Comparing java.sql.timestamp values
- Why is the ++: operator in the Scala language so strange?
- What type of expression is this in scala?
- Getting a HashMap from Scala's HashMap.mapValues?
- Scala: Use map function tuples in a subsequent flatMap
- Primary constructor parameter declared using val allows to change the value
- Spark SQL: automatic schema from csv
- Spark: Convert column of string to an array
- Does Apache spark 2.2 supports user-defined type (UDT)?
- (scala) Can not found registered table spark sql
- Scalding tutorial: java.lang.ClassNotFoundException
- How to join two spark RDD