dimanche 1 septembre 2019

How to deserialize twitter response to List

I'm using rest-assured and twitter4j for testing twitter API. All calls are made via RestAssured, twitter4j is used for Json response deserialization. And what I want to do is to deserialize Json response from twitter - GET statuses/home_timeline which returns Array of Status objects(from twitter4j).

I can easily deserialize one Status object like here:

@Test
public void verifyTwitCreation() {

    RequestSpecification spec = new RqBuilder()
            .withStatus(textToPublish)
            .build();

    Response response = twitClient.createTwit(spec);

    assertResponseCode(response, 200);

    String json = response.getBody().asString();
    Status status = null;

    try {
        status = TwitterObjectFactory.createStatus(json);
    } catch (TwitterException e) {
        e.printStackTrace();
    }
    System.out.println(status.toString());
}

But I don't know how to do the same for deserializing array of such Status objects.

Aucun commentaire:

Enregistrer un commentaire