1

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?

art-solopov
  • 4,289
  • 3
  • 25
  • 44

1 Answers1

5

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 {
      // ...
    }
  });
tsegismont
  • 8,591
  • 1
  • 17
  • 27