我正在使用Kotlin
并且Vert.x
我有:
data class Product(
var id: UUID? = UUID.randomUUID(),
var name: String? = null,
@JsonFormat(shape=JsonFormat.Shape.ARRAY)
var pictures: JsonArray? = JsonArray()
)
我正在尝试Array
在pictures
. 我在请求正文中的 JSON 是这样的:
{
"name": "Test",
"pictures": [{"test": "a"}]
}
当我发送上面类似的Object
内部消息时Array
,我收到此错误:
[ERROR] 2020-01-02 13:04:26.519 [vert.x-eventloop-thread-0] Route - io.vertx.core.json.DecodeException: Failed to decode:Cannot deserialize instance of `java.util.ArrayList<java.lang.Object>` out of START_OBJECT token
at [Source: (String)"{
"name": "Test",
"pictures": [{"test": "a"}]
}
"; line: 8, column: 15] (through reference chain: br.com.test.api.product.Product["pictures"]->io.vertx.core.json.JsonArray["list"])
但是如果我像这样发送一个空的Array
,它的工作原理:
{
"name": "Test",
"pictures": []
}
我收到正确的回复:
{"id":"a6d2d319-42a9-4d4a-b16a-6bf4eb76e36d","name":"Test","pictures":[]}
所以问题是,我怎样才能在我的客户中发布Array
一个Objects
?谢谢!