Java Reference
In-Depth Information
The easiest and most straightforward way of using these methods is to use strings.
For example, we can invoke the find_JSON(Class<T> responseType, String id)
as follows:
public class Main {
public static void main(String[] args) {
NewJerseyClient newJerseyClient = new NewJerseyClient();
String response = newJerseyClient.find_JSON(
String.class, "1");
System.out.println("response is: " + response);
The preceding invocation will return a string containing a JSON representation of the
values in the row with an ID of 1 in the database. On executing the code, we should
see the following output:
response is: {"addressline1":"111 E. Las Olivas
Blvd","addressline2":"Suite 51","city":"Fort Lauderdale","creditLimit"
Eagle Corp","phone":"305-555-0188","state":"FL","zip":{"areaLength":54
We can then parse and manipulate the JSON response as usual.
Additionally, we can send data to our web service in JSON or XML format; all we
need to do is create a string with the appropriate JSON or XML and pass it to one
of the generated methods. For example, we could insert a row into the database by
using the following code:
package com.ensode.netbeansbook.jaxrsclient;
public class Main1 {
public static void main(String[] args) {
String json = "{\"addressline1\":\"123 Icant Dr.\","
+ "\"addressline2\":\"Apt 42\",\"city\":"
+ "\"Springfield\",\"creditLimit\":1000,"
Search WWH ::

Custom Search