我正在尝试使用@GET @Produces api方法在StateandRef中的多个值中仅显示JSON对象值。但是无法从中检索特定值。请帮帮我。
答案 0 :(得分:0)
以下是IOUState
的示例。我们将保险库中的每个IOUState
映射到一个简单数据类的实例,然后我们将其作为JSON返回。
IOUStateData
数据类
data class IOUStateData(
val value: Int,
val lender: Party,
val borrower: Party
)
终端
@GET
@Path("ious")
@Produces(MediaType.APPLICATION_JSON)
fun getIOUs(): Map<String, List<IOUStateData>> {
// Extract the IOUState StateAndRefs from the vault.
val iouStateAndRefs = rpcOps.vaultQueryBy<IOUState>().states
// Map each StateAndRef to its IOUState.
val iouStates = iouStateAndRefs.map { it.state.data }
// Map each IOUState to a data class that will be returned as JSON.
val iouStateDatas = iouStates.map { iouState ->
IOUStateData(iouState.value, iouState.lender, iouState.borrower)
}
return mapOf("iouStates" to iouStateDatas)
}