vendredi 6 mars 2020

how can i filter the specific Object attribute at runtime in java

suppose i've a class

public class someDto<T> {
    private List<ApiLink> links = null;
    private T _fields;
}

suppose _fields has mapped values like

"_fields": {
            "key1": "20",
            "key2": "181",
            "key3": "19",
            "key4": "19",
}

now i have a list where i've list of attribute i need

List<String> ListofAttributeIneed
[key2,key4]

so now i want that the _field of someDto class will give me only ListofAttributeIneed data not all

I'm thinking of the approach first cast/convert T _fields to some map and the a new map which will have only these key then cast/convert that map back to T _fields but that seems dirty way





Aucun commentaire:

Enregistrer un commentaire