JAX-RS Post multiple objects

You can not use your method like this as correctly stated by Tarlog. However, you can do this: @POST @Path(“test”) @Consumes(MediaType.APPLICATION_JSON) public void test(List<ObjectOne> objects) or this: @POST @Path(“test”) @Consumes(MediaType.APPLICATION_JSON) public void test(BeanWithObjectOneAndObjectTwo containerObject) Furthermore, you can always combine your method with GET parameters: @POST @Path(“test”) @Consumes(MediaType.APPLICATION_JSON) public void test(List<ObjectOne> objects, @QueryParam(“objectTwoId”) long objectTwoId)

How to handle CORS using JAX-RS with Jersey

Note: Make sure to read the UPDATE at the bottom. The original answer includes a “lazy” implementation of the CORS filter With Jersey, to handle CORS, you can just use a ContainerResponseFilter. The ContainerResponseFilter for Jersey 1.x and 2.x are a bit different. Since you haven’t mentioned which version you’re using, I’ll post both. Make … Read more

How to set up JAX-RS Application using annotations only (no web.xml)?

** PLEASE READ IF YOU USE TOMCAT OR JETTY! ** The accepted answer does work, but only if the webapp is deployed to an app server like Glassfish or Wildfly, and possibly servlet containers with EE extensions like TomEE. It doesn’t work on standard servlet containers like Tomcat, which I’m sure most people looking for … Read more

Required @QueryParam in JAX-RS (and what to do in their absence)

Good question. Unfortunately (or maybe fortunately) there is no mechanism in JAX-RS to make any params mandatory. If a parameter is not supplied it’s value will be NULL and your resource should deal with it accordingly. I would recommend to use WebApplicationException to inform your users: @GET @Path(“/some-path”) public String read(@QueryParam(“name”) String name) { if … Read more

Why use JAX-RS / Jersey?

Why use JAX-RS / Jersey? Short Answer Because it makes the development of RESTful services easier. Long Answer JAX-RS is a standard that makes it easy to create a RESTful service that can be deployed to any Java application server: GlassFish, WebLogic, WebSphere, JBoss, etc. JAX-RS is part of Java EE, and when JAX-RS is … Read more

What exactly is the ResourceConfig class in Jersey 2?

Standard JAX-RS uses an Application as its configuration class. ResourceConfig extends Application. There are three main ways (in a servlet container) to configure Jersey (JAX-RS): With only web.xml With both web.xml and an Application/ResourceConfig class With only an Application/ResourceConfig class annotated with @ApplicationPath. With only web.xml It is possible to configure the application in a … Read more

How can I grab all query parameters in Jersey JaxRS?

You can access a single param via @QueryParam(“name”) or all of the params via the context: @POST public Response postSomething(@QueryParam(“name”) String name, @Context UriInfo uriInfo, String content) { MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); String nameParam = queryParams.getFirst(“name”); } The key is the @Context jax-rs annotation, which can be used to access: UriInfo, Request, HttpHeaders, SecurityContext, … Read more