O'Reilly logo

Developing Middleware in Java EE 8 by Abdalla Mahmoud

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Returning JSON

Let's try to return our first JSON object with JAX-RS. It is so easy that you don't need to handle any special stuff yourself, just return your object from a method declared to return JSON's media type using the @Produces annotation, nothing more!

In the following example, we are going to simulate an in-memory database of movies using a HashMap. We are going to create a map of movies, where the key is the movie's id (primary key), and the value is an object representing a movie in some database. We will support two operations in this example:

  • Retrieving a movie by id
  • Listing all movies found in our database

Before we go on with this example, let's discuss how we should design our RESTful services. The dominant convention ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required