如何在REST Web服务中传递和接收用户定义的类

时间:2012-02-28 12:18:52

标签: web-services rest

我正在学习REST Web服务。我想知道有没有办法传递用户定义的class.i我不使用spring在这里,我可以传递JSON和Xml,但任何方式来传递用户定义的类。通过以下代码传递JSON类。

HttpPost httpPost = new HttpPost("url to REST services method");
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("json", jsonObj.toString()));//some json object 
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams);
entity.setContentEncoding(HTTP.UTF_8);
entity.setContentType("application/json");

httpPost.setEntity(entity);// here we set param as entity in httpPost

httpPost.setHeader("Content-Type", contentType);
httpPost.setHeader("Accept", contentType);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();

在上面的例子中我们已经将JSON对象设置为httpPost,但是如果想要传递用户定义的类如何设置'httpPost.setEntity'以及我应该提到的contentType是什么。

0 个答案:

没有答案