Input and Output binary streams using JERSEY?

I managed to get a ZIP file or a PDF file by extending the StreamingOutput object. Here is some sample code: @Path(“PDF-file.pdf/”) @GET @Produces({“application/pdf”}) public StreamingOutput getPDF() throws Exception { return new StreamingOutput() { public void write(OutputStream output) throws IOException, WebApplicationException { try { PDFGenerator generator = new PDFGenerator(getEntity()); generator.generatePDF(output); } catch (Exception e) { … Read more

How to access parameters in a RESTful POST method

Your @POST method should be accepting a JSON object instead of a string. Jersey uses JAXB to support marshaling and unmarshaling JSON objects (see the jersey docs for details). Create a class like: @XmlRootElement public class MyJaxBean { @XmlElement public String param1; @XmlElement public String param2; } Then your @POST method would look like the … Read more

REST API DESIGN – Getting a resource through REST with different parameters but same url pattern

In my experience, GET /users/{id} GET /users/email/{email} is the most common approach. I would also expect the methods to return a 404 Not Found if a user doesn’t exist with the provided id or email. I wouldn’t be surprised to see GET /users/id/{id}, either (though in my opinion, it is redundant). Comments on the other … Read more

What does Provider in JAX-RS mean?

Providers are a simply a way of extending and customizing the JAX-RS runtime. You can think of them as plugins that (potentially) alter the behavior of the runtime, in order to accomplish a set of (program defined) goals. Providers are not the same as resources classes, they exist, conceptually, at a level in-between resources classes … Read more

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

The problem is the JSON – this cannot, by default, be deserialized into a Collection because it’s not actually a JSON Array – that would look like this: [ { “name”: “Test order1”, “detail”: “ahk ks” }, { “name”: “Test order2”, “detail”: “Fisteku” } ] Since you’re not controlling the exact process of deserialization (RestEasy … Read more

Difference between JAX-RS and Spring Rest

JAX-RS JAX-RS is a specification for implementing REST web services in Java, currently defined by the JSR-370. It is part of the Java EE technologies, currently defined by the JSR 366. Jersey (shipped with GlassFish and Payara) is the JAX-RS reference implementation, however there are other implementations such as RESTEasy (shipped with JBoss EAP and … Read more

URL matrix parameters vs. query parameters

The important difference is that matrix parameters apply to a particular path element while query parameters apply to the request as a whole. This comes into play when making a complex REST-style query to multiple levels of resources and sub-resources: http://example.com/res/categories;name=foo/objects;name=green/?page=1 It really comes down to namespacing. Note: The ‘levels’ of resources here are categories … Read more