I am working on a GWT project and are a bit confused. Its a server/client project. I am handling the json with Autobean. Autobean needs to use interfaces to work. I haven't work so much with interfaces before and need some help. This is how the Autobean code:
interface User {
int id();
void setId(int id);
String getUsername();
void setUsername(String username);
}
interface Result{
List<User> getUsers();
void setUsers(List<User> users);
}
interface Beanery extends AutoBeanFactory{
AutoBean<User> makeBean();
AutoBean<Result> makeBeans();
}
To convert the json to the a List I do this.
AutoBean<Result> autoBeanCloneAB = AutoBeanCodex.decode(beanFactory, Result.class, "{\"users\": " + json + "}" );
List<User> users = autoBeanCloneAB.as().getUsers();
I am also having a User class, and I am unsure if this is unnecessary or how I should be handling this.
public class User {
private int id;
private String username;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
I have in all my earlier projects only been working with model classes and not interfaces. I have tried to read and seem to understand the concept of an interface, but in this case i cannot see any reason to use the User class when I have the User interface. What is the right approach? Is there any purpose of using a the User class, and if yes, please explain.
As usual. All help is appreciated