1
I’m making an ajax requisition 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:
// ...
Note that Against
is a trivial Enum:
public enum Against {
ANYBODY, ANY_FRIEND, A_FRIEND;
}
My doubt: is it possible to receive Enum directly, as in the example below? Do you know any changes in 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:
// ...
It doesn’t exactly look like I wanted it to, because I still have to keep the
MediaType.APPLICATION_FORM_URLENCODED
and the@FormParam
, but already improves considerably. Thank you.– André
@André I added one more option. See if you can help. Unfortunately I’m a little out of time to make a functional example, but if you can understand how the
MessageBodyReader
, will probably solve your problem.– utluiz