How can I send an array of strings from client to jersey server? My server method looks like this:
@POST
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<User> createUpdateUser(@NotNull @BeanParam User user) {
siteDao.addUser(user);
Collection<User> l = siteDao.listSites();
ArrayList<User> al = new ArrayList<User>(l);
return al;
}
User object contains the array of strings - see below.
My Java Script client method (inside my index.html) to prepare user object to be sent to server looks like this:
function getFormUserDetails() {
var user = {
servingDates: ['jan','feb']
}
return user;
}
My ajax call to the server looks like this:
$(document).ready(() => {
$('#addUserButtonId').on('click touchstart', (event) => {
var user = getFormUserDetails();
$.ajax({
url: "http://localhost:8080/remote-loader/App/User/",
type: 'POST',
data: user,
}).done((data, textStatus, xhr) => {
// some code here
}).fail((jqXhr, textStatus, errorThrown) => {
console.log( errorThrown );
}).always(() => {
});
});
});
My User class looks like this:
public class User /* implements Serializable */ {
@FormParam("servingDates")
private List<String> servingDates = new ArrayList<String>();
public List<String> getServingDates() {
return servingDates;
}
public void setServingDates(List<String> servingDates) {
this.servingDates = servingDates;
}
}
The problem I am facing is that user object when method createUpdateUser is called by Jersey contains an empty servingDates array.