[英]Play Json: Transforming a Reads[T] to Reads[Seq[T]] without implicits
I hava a Reads[T]
. 我有一个
Reads[T]
。 I would like to parse a Json object which is expected to be an array of T
's. 我想解析一个Json对象,它应该是一个
T
的数组。 Is there a simple way to obtain a Reads[Seq[T]]
without defining my Reads[T]
as implicit? 是否有一种简单的方法来获取
Reads[Seq[T]]
而不将我的Reads[T]
定义为隐式? Essentially, I am looking for a function that takes Reads[T]
and returns Reads[Seq[T]]
. 本质上,我正在寻找一个函数,它接受
Reads[T]
并返回Reads[Seq[T]]
。
I came across Reads.TraversableReads
, and thought that I can pass the implicit reader it needs explicitly, but this function also wants a CanBuildForm[...]
, which does not sound like fun. 我遇到了
Reads.TraversableReads
,并认为我可以明确地传递它需要的隐式阅读器,但是这个函数也需要一个CanBuildForm[...]
,听起来不是很有趣。
There is a method for this in the Reads
companion object: Reads.seq
. Reads
伴侣对象中有一个方法: Reads.seq
。 Its parameter is usually implicit, but you can always call it explicitly if you want: 它的参数通常是隐式的,但如果你想要,你总是可以明确地调用它:
val a: Reads[T] = ...
val b: Reads[Seq[T]] = Reads.seq(a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.