These are chat archives for argonaut-io/argonaut

21st
Jun 2017
Andreas Jim-Hartmann
@devkat
Jun 21 2017 09:14
hi, quick question:
Parse.decodeOption[Map[String, Seq[String]]](jsonString)
doesn’t compile since it is missing the implicit EncodeJson for this type
I tried adding a CodecJson for Seq[A] (based on List), but it didn’t help
any hints? TIA!
I’m using version 6.2 BTW
Colt Frederickson
@coltfred
Jun 21 2017 12:43

@devkat This in general is a bad place to get help. I've tried a few times and have failed. In this case I think I can help you. If you really wanted to deserialize the Seq version you just need an implicit for "Seq".


scala> implicit def SeqDecodeJson[A](implicit e: DecodeJson[A]): DecodeJson[Seq[A]] = CanBuildFromDecodeJson[A, Seq]
SeqDecodeJson: [A](implicit e: argonaut.DecodeJson[A])argonaut.DecodeJson[Seq[A]]

scala> Parse.decodeOption[Map[String, Seq[String]]]("""{"foo":["bar","baz"]}""")
res4: Option[Map[String,Seq[String]]] = Some(Map(foo -> Vector(bar, baz)))

But remember that if you just deserialize as a Vector or List you can refer to it as a Seq.

scala> val x: Option[Map[String, Seq[String]]] = Parse.decodeOption[Map[String, Vector[String]]]("""{"key": ["value1", "value2"]}""")
x: Option[Map[String,Seq[String]]] = Some(Map(key -> Vector(value1, value2)))

This is because Vector is a Seq.

Andreas Jim-Hartmann
@devkat
Jun 21 2017 13:52
@coltfred, thanks a lot for your reply!