Covert object of pojo Class A to the object of pojo class b if there parameters are same

90 Views Asked by At

I am sure this question might have been asked couple of times here but I am not understanding what query I should use.Here i need to convert the object of one model class A to the object of another model class B. Like

Class A{
String Name;
String Data;
List<String> roleIds;
String id
}

And another class with same parameters

Class B{
String Name;
String Data;
List<String> roleIds;
String id
}

E.g. A a= new A();

B b =a;

One solution that i knew is Interface that i can use in both class and then use their object.But i need to know is there any other solution for that in Android to achieve that ?

I hope i am able to covey my question .Please help me to understand.

1

There are 1 best solutions below

0
On

I don't understand why you need such a behavior, you can use the same Class and clone

they are different type class and need different space in memory, so in the clean code you are not able to do this but one way is to use Gson convert it to json and then back to other class but it is very very bad way.

there are other ways but they won't be clean code

so I wish you don't do this as above