We have a common API to get the payload(consider JSON) along with client ID from different clients.
How can I convert the payload to appropriate POJO using client ID.
Rough Idea is to deserialise the payload as java object and based on the clientId, convert the JAVA object to respective POJO.
I have a ENUM class in place for the config which looks something as follows.
public enum SourceEnum {
ClientId1(A.class);
ClientId2(B.class);
Class clazz;
SourceEnum(Class clazz) {
this.clazz = clazz;
}
public Class getClazz(){
return this.clazz;
}
}
We can use SourceEnum.valueOf(clientId).getClazz() to get the Class.
How can I use this information to convert the java Object to respective class object?
And is this the correct way of solving this problem? Want to try out if there are any better ways of solving this