我需要使用List [Long]中的JsArray创建一个JsObject。我虽然有一些名为- for each possible query param
- get its value from the request
- if value is present build predicate which
- gets field value from detail object and convert to string
- check that both strings (queried and extracted) matches
- if value is not present return predicate that always returns true
- combine resulting predicates using and
- use always true as fallback (which here never actually happens)
JsLong
显然没有。有什么建议我可以创建吗?
答案 0 :(得分:0)
JavaScript / JSON中只有一种数字类型,Number
。看起来你正在使用Play-JSON,它有JsNumber
,可以用BigDecimal
构建。 (只需将Long
转换为BigDecimal
)。
import play.api.libs.json._
def someWork(someList: List[Long]): JsObject = {
Json.obj(
"someField" -> JsArray(someList.map(a => JsNumber.apply(BigDecimal(a))))
)
}
scala> someWork(List(1, 2, 3, 4))
res0: play.api.libs.json.JsObject = {"someField":[1,2,3,4]}