The background to my problem is: My app is calling a SOAP webservice and retrieving different responses depending on which method is called. Depending on the answer I would like to parse the response into objectA or objectB. To make the parsing of the response as simple as possible I would like to be able to get all fields of a certain class and then create an instance of that class and set the variables.
Example: Lets say i have a class
Person with variables
name. If the soap response has a tag <name>Bob</name> I would like to be able to set the name field in class Person.
This is possible in java/android with the following code.
Code:
// get fields of class
Class<? extends Object> theClass = myClass.getClass();
Field[] fields = theClass.getDeclaredFields();
// Set value for a specific field
fields[i].set(myClass, strValue);
String tag = fields[i].getName()
One way I thought was to make a general set method for my objects set(field, value). And use that in order to set the specific field. But I would like to use a native method if possible.
Hope someone can help me with this.
Thanks