你應該可以使用任何你想要的Java休息客戶端。我個人喜歡使用球衣,因爲有時在Eclipse中使用Spring框架可能會很痛苦。
它爲我將所有這些librairies:
lib/jsr311-api-1.1.1.jar,
lib/jersey-client-1.19.jar,
lib/jersey-core-1.19.jar,
lib/jersey-json-1.19.jar,
lib/jackson-core-asl-1.9.2.jar,
lib/jackson-jaxrs-1.9.2.jar,
lib/jackson-mapper-asl-1.9.2.jar,
lib/jaxb-api-2.2.2.jar,
lib/jaxb-impl-2.2.3-1.jar,
lib/jackson-xc-1.9.2.jar
和一個簡單的調用如下:
try {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
WebResource webResource = client.resource("http://localhost:8080/getMyObject");
ClientResponse response = webResource.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
MyObject output = response.getEntity(MyObject.class);
} catch (Exception e) {
//Handling errors
}
JSONConfiguration.FEATURE_POJO_MAPPING是自動映射使用的球衣,JSON以JSON和jackson - *。jar