我正在学习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是什么。