-1

I would like to implement a universal Data Model class which will have one attribute of type string and it will contain the entire server json response

So I am a junior android developer and the question i have in mind is that i have to create a different data model class for different server response. so i thought of a workaround and created a single data model for all my view using adapters to inflate data. Now this data model class has only one attribute of type string and it will contain the entire json response i get from my api which i can parse later in my adapters.

I just want to know if my approach is wrong or is it much cleaner practice. and/or are there any performance benefits?

Shayan khan
  • 311
  • 5
  • 12

1 Answers1

0

try creating a generic class like

public Response<T> {
  String status;
  T data;
  String error;
}

And instead of parsing response manually use Gson library to convert your Json to a model class and then pass the model to adapters