Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand what you are trying to do then you've written a lot of code that is not very useful for what you are trying to accomplish. For one, you're only supposed to define resource classes on the server side. And secondly, calling them directly is fraught with problems, they are server components that are supposed to be invoked by a <em>container</em>.</p> <p>Good news is, the Jersey client is quite robust. It will automatically serialize your objects to an appropriate format, as long as its setup right. In your case, you want to make sure you are including the jersey-json JAR in your client. If you are, then you can have it automatically convert your object to JSON with the following code:</p> <pre><code>Company domainObject = companyDAO.findCompanyById(id); ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON) .entity(domainObject, MediaType.APPLICATION_JSON) .post(ClientResponse.class); </code></pre> <p>This code presumes that the server is responding with an instance of <code>ClientResponse</code>. Also note that you need the jersey-json and Jackson JAR's in your client classpath in order for this to work. If using Maven its sufficient to include these dependencies:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt; &lt;artifactId&gt;jersey-core&lt;/artifactId&gt; &lt;version&gt;1.17&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt; &lt;artifactId&gt;jersey-client&lt;/artifactId&gt; &lt;version&gt;1.17&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt; &lt;artifactId&gt;jersey-json&lt;/artifactId&gt; &lt;version&gt;1.17&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Otherwise, you need to manually include all the right JAR's, minimum set:</p> <ul> <li>jackson-core-asl-1.9.2.jar</li> <li>jackson-jaxrs-1.9.2.jar</li> <li>jackson-mapper-asl-1.9.2.jar</li> <li>jackson-xc-1.9.2.jar</li> <li>jersey-core-1.14.jar</li> <li>jersey-json-1.14.jar</li> <li>jersey-server-1.14.jar</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload