I am making an ajax request like this:
$.ajax({
type : 'POST',
url : apiURL + '/play',
dataType : "json",
data : {
against : "ANYBODY"
},
success : function(data, textStatus, jqXHR) {
// ...
},
error : function(jqXHR, textStatus, errorThrown) {
// ...
},
});
And receiving (successfully) the data on the server like this:
@POST
@Path("play")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Game play(@FormParam("against") String param) {
Against against = Against.valueOf(param);
switch(against) {
case ANYBODY:
// ...
Notice that Against
is a trivial enum:
public enum Against {
ANYBODY, ANY_FRIEND, A_FRIEND;
}
My question: Is it possible to receive the enum directly, as in the example below? Do you know any changes in the javascript and / or java code that allow me to do this?
@POST
@Path("play")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Game play(Against against) {
switch(against) {
case ANYBODY:
// ...