Q:

Be able to loop every user returned from json response with jackson

Im using jackson to map my json response to a POJO, but i'm having issues when i try to loop the returned list from my object mapper.
public List<T> getAll() {
    try {
        return mapper.readValue(url, new TypeReference<Collection<T>>() {});
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

Error:
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to br.com.realmpvp.commons.domain.User

Sample JSON:

    [{
        "id": {
            "timestamp": 1529630399,
            "machineIdentifier": 8647350,
            "processIdentifier": 1524,
            "counter": 321373,
            "time": 1529630399000,
            "date": 1529630399000,
            "timeSecond": 1529630399
        },
        "cash": 0,
        "currentUsername": "teste6",
        "ip": "0.0.0.0",
        "geolocation": "Portugal",
        "password": "teste",
        "usernameHistory": [
            "testeeeeeee",
            "fdsa"
        ]
    }]

What i want to be able to do:
    List<User> users = info.getAll();

    for(User u : users){
        System.out.println(u.getCurrentUsername());
    }

A:

Try to do so:
List<T> myUnits = objectMapper.readValue(json, objectMapper.getTypeFactory().
        constructCollectionType(List.class, T.class));

I don't sure, if you can use Generics here.

