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);
newJerseyClient.close();
}
}
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"
:100000,"customerId":1,"discountCode":{"discountCode":"N","rate":0.00
},"email":"jumboeagle@example.com","fax":"305-555-0189","name":"Jumbo
Eagle Corp","phone":"305-555-0188","state":"FL","zip":{"areaLength":54
7.967,"areaWidth":468.858,"radius":755.778,"zipCode":"95117"}}
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;
import javax.ws.rs.ClientErrorException;
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