Processing JSON in a RESTful web service

The JSON format is commonly used in RESTful web services to exchange messages. In this section, we will discuss how the Java API or JSON processing is used in a RESTful web service. First, add the RESTful web service dependency to pom.xml:

    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
      <version>2.0</version>
    </dependency>

Create a sample REST web service to test the JSON API. Create a resource class JsonResource annotated with @PATH to identify the URI path. Here's how we accomplish this:

package org.json; import java.io.StringReader; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.Path; import javax.json.*; import javax.ws.rs.Consumes; import ...

Get Advanced Java® EE Development with WildFly® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.