想知道有没有什么方法可以复用一些Java反射API/SOAP/web服务内部函数或者外部API来实现:
- 有一个对象列表,从网络上的方法获得
- 通过 config 有一个对应于这些对象的类列表
- 属性必须用 1 填充的 pojo
有没有通用的+几行的方式来做到这一点?
例子
void process(Object pojoToFill, Class[] classesOfSetters, Objects[] values) {
//what to do here to fill up pojoToFill with values using classesOfSetters, in a generic way?
}
void sample() {
Object []objects;// filled with values that are needed by Person class, sent over the wire, setters
Class []propertyClasses = new Class[String.class, Address.class]//from config
Person person = new Person();
process(person, propertyClasses, objects);
}
public class Person {
private String name;
private Address address;// etc
// getters and setters
}
class Address {
private String line1;// other properties and getters and setters
}