本文介绍了播放Json:在没有隐式的情况下将Reads [T]转换为Reads [Seq [T]]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个Reads[T].我想解析一个Json对象,该对象应该是T的数组.是否有一种简单的方法来获取没有定义我的Reads[T]为隐式的Reads[Seq[T]] ?本质上,我正在寻找一个使用Reads[T]并返回Reads[Seq[T]]的函数.

I hava a Reads[T]. I would like to parse a Json object which is expected to be an array of T's. Is there a simple way to obtain a Reads[Seq[T]] without defining my Reads[T] as implicit? Essentially, I am looking for a function that takes Reads[T] and returns Reads[Seq[T]].

我遇到了Reads.TraversableReads,并认为我可以显式地传递它需要的隐式阅读器,但是此功能还需要一个CanBuildForm[...],听起来并不有趣.

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随播对象Reads.seq中有一种用于此目的的方法.它的参数通常是隐式的,但是如果需要,您始终可以显式调用它:

There is a method for this in the Reads companion object: 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)

这篇关于播放Json:在没有隐式的情况下将Reads [T]转换为Reads [Seq [T]]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 13:37