I’m writing resfull web service vai Jersey. Returning data in json.
Web service has 2 method, first returns User object and Second ArrayList of User Object;
This is my User Class
public class User {
private int id;
private String firstName;
private String surName;
private String address;
private int status
}
The problem is that i want to return User with only id, firtName and surName in the first method, output example: {"id":"1","firstName":"William","surName":"Dodgson"}
and UserList with id, address in the second method,
output example:
[{"id":"1","address":"some address"}, {"id":"2","address":"some address"}]
How should i manage this ?
I don’t know jersey. But you can divide that class with inheritance.
Firt create a base user class :
And extended class
Finally in each method you can return distinct object.