You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val nt: (name: String, age: Int) = (name = "Simon", age = 40)
given fooDecoder1: Decoder[Foo] =
deriveDecoder[(name: String, age: Int)]
and it's error
[{
"resource": "/Users/simon/Code/namedTupleTest/nt.scala",
"owner": "_generated_diagnostic_collection_name_#3",
"code": "172",
"severity": 8,
"message": "No given instance of type scala.deriving.Mirror.Of[(name : String, age : Int)] was found for parameter A of method deriveDecoder in object semiauto. Failed to synthesize an instance of type scala.deriving.Mirror.Of[(name : String, age : Int)]:\n\t* class Any is not a generic product because it is not a case class\n\t* class Any is not a generic sum because it is not a sealed class",
"source": "bloop",
"startLineNumber": 31,
"startColumn": 44,
"endLineNumber": 31,
"endColumn": 44
}]
With I guess the (slightly tedious?) workaround;
given fooDecoder1: Decoder[(name: String, age: Int)] =
new Decoder[(name: String, age: Int)] {
def apply(c: HCursor): Decoder.Result[(name: String, age: Int)] =
for {
name <- c.downField("name").as[String]
age <- c.downField("age").as[Int]
} yield (name, age)
}
given fooEncoder1: Encoder[(name: String, age: Int)] =
new Encoder[(name: String, age: Int)] {
def apply(a: (name: String, age: Int)): Json =
Json.obj(
"name" -> Json.fromString(a.name),
"age" -> Json.fromInt(a.age)
)
}
The text was updated successfully, but these errors were encountered:
Quafadas
changed the title
Support NamedTuples ?
Support deriving Encoder / Decoder for NamedTuples ?
Nov 8, 2024
Just pointing out the more more or less obvious here: the general problem with library support for named tuples is: library authors are encouraged to publish for LTS scala versions (currently: 3.3.x) "unless your library is built around some new language feature available only on Next". So to add such support, there would be three options:
wait until a new LTS version (>3.6.x) is out
do not follow the official recommendations and up the scala version to 3.6.x (seems like a bad idea)
publish the specific feature in a deficated 3.6.x-module while the rest of the library remains on 3.3.x
Here's the (trivial) example...
and it's error
With I guess the (slightly tedious?) workaround;
The text was updated successfully, but these errors were encountered: