I have a User and School Class,
public class User {
private Long id;
@Property("complete_name")
private String name;
private List<School> schools;
....
}
public class School {
private Long id;
private Sting name;
private String otherInfo;
}
I want to update User, School and any other object using a single call. As I do want to make my clients dynamically handle stuff.
I think of a way for this, my declare two call 1 will get all fields and theirs types and other will be able to update the data,
Update looks like
Call 1:
/update?method=editProfile
Body
{data:[{id:1},{name:"XYZ"}]}
Call 2:
/update?method=editBrand
Body
{data:[{id:1},{otherInfo:"Some Info"}]}
I call the method using update with method name and params and using reflection load the method and also able to load the fields,
Need help in
1) How can I update fields based on annotated field value e.g complete_name/name
2) How I can validate data in JSON body
3) Whats the best way/json for complex objects.
I think you’ve got more than one question here and taken as a whole it’s a bit hard to answer but:
The simplest is probably to have the client send a complete json-ized User structure each time which you can then use to build a Java object (using Jackson), then validate it before updating the version on the server side. Remember to always validate on the server, don’t rely on Javascript in the client!
If this is too inefficient you can then look at doing incremental updates.
Hopefully that can get you started.