2

I have the following Enum class

public enum EventAccess {
            PUBLIC("PUBLIC"),
            EMPLOYEES_ONLY("EMPLOYEES_ONLY"),

String name;
private EventAccess(String name) {
    this.name = name;
}
public String getName() {
    return name;
   }
 }

Also i have a Serializable class that that has the enum as one of its fields

 public class EventAccessRequest implements Serializable{

private List<EventAccess> event_access = new ArrayList<>();

public EventAccessRequest() {

}

public List<EventAccess> getEvent_access() {
    return event_access;
}

public void setEvent_access(List<EventAccess> event_access) {
    this.event_access = event_access;
  }
}

I have an @Api method that has creates an object the of type EventAccessRequest. I set the value of this request in the Api Explorer but it does no set any enum field i put in it.

@ApiMethod(name = "fetchEventByEventAccess", path = "user/events/list-by-access/", httpMethod = HttpMethod.GET)
    public RestfulResponse fetchEventByEventAccess(EventAccessRequest request)throws Exception
    {

            EventAccess x = request.getEvent_access().get(0);

            return new RestfulResponse(Status.SUCCESS, "Events retrieved",request, 200);
        }

    }

I have tried inserting other types which is not enum and it sets their value but when I try inserting an Enum in Api exploere in does not set the value. and so my request object is always empty.

What could be the problem?

Theophilus Omoregbee
  • 2,463
  • 1
  • 22
  • 33
oziomajnr
  • 1,671
  • 1
  • 15
  • 39

1 Answers1

5

The error was that you were using the httpMethod = HttpMethod.GET instead of httpMethod = HttpMethod.POST since u are sending a pay load request, you will need to make your http method to wait for post request to accept payload or request body

so it should be

@ApiMethod(name = "fetchEventByEventAccess", path = "user/events/list-by-access/", httpMethod = HttpMethod.POST)

observe the httpMethod thanks.

Theophilus Omoregbee
  • 2,463
  • 1
  • 22
  • 33