In Vert.x Web client manual there's an example of decoding an incoming JSON response into a POJO:
client
.get(8080, "myserver.mycompany.com", "/some-uri")
.as(BodyCodec.json(User.class))
.send(ar -> {
// Process the response
})
Is there a way to decode an incoming JSON array into a collection of objects?
I don't believe you can use a BodyCodec
to convert the content straight to a collection of objects.
However you use Vert.x core Json
class with the body as Buffer
client
.get(8080, "myserver.mycompany.com", "/some-uri")
.send(ar -> {
if (ar.succeeded()) {
Buffer body = ar.result().body();
List<User> users = Json.decodeValue(body, new TypeReference<List<User>>() {});
} else {
// ...
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.