A - The type of the origin bean of the copy.B - The type of the target bean of the copy.public interface BeanCopier<A,B>
You can define copiers by extending this interface.
Imagine you have the following java bean classes defined as:
public class Person {
private String name;
private int age;
public String getName(){return name;}
public void setName(String name){this.name = name;}
public int getAge(){return age;}
public void setAge(int age){this.age = age;}
}
public class User {
private String login;
private String name;
private int age;
public String getLogin(){return login;}
public void setLogin(String login){this.login = login;}
public String getName(){return name;}
public void setName(String name){this.name = name;}
public int getAge(){return age;}
public void setAge(int age){this.age = age;}
}
You can define the following interface to make copies between objects of the type Person to/from objects of type User, considering its property values:
public interface PersonCopier extends BeanCopier{}
To use the copier, just call GWT.create on the given interface, or inject it on your class.
public class MyController {
@Inject
private PersonCopier copier;
@Expose
public void myMethod() {
// read two objects...
copier.copyTo(person, user);
copier.copyFrom(user, person);
}
}
}
Note, on the above example, that class User has a property login and Person class does not. No problem, that property will be ignored during copies.
Copyright © 2015. All rights reserved.