0

I have below RestFul web service method devleoped using Jersey.

@GET
@Produces ("application/xml")
public User validateAndReturn(User  user) {
User als=null;
try {
als= UserService.validate(user);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return als;
}

Here User.java class is not generated from xsd and is handwritten. In this case how clients would call my web service? Do they need User.java and populate it through setters and getters?

Thanks!

user755806
  • 6,565
  • 27
  • 106
  • 153
  • possible duplicate of [Rest clients for Java?](http://stackoverflow.com/questions/221442/rest-clients-for-java) –  Dec 23 '13 at 12:24

1 Answers1

0

You need to share User object details with your client. Choice is yours, in which way you do.

XML schema representation is used because that is language independent. It allows clients written in different technology to create their own input object confirming to the schema. Almost all the languages provide libraries to generate classes from xml these days.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • Juned, clients need to populate the request as: User u = new User();//populate object using setters... am i right? Also, if we dont supply User then there is no way that they can call my REST method right? Thanks! – user755806 Dec 23 '13 at 12:26
  • @user755806 If both your client and server are in java then i think it is acceptable to share the common classes. As I believe, it will be a good appraoch to package all your common classes to be part of one jar that is used by both client and server. – Juned Ahsan Dec 24 '13 at 03:45