title: Send and receive JSON to REST WebService in Jersey Java
body: <p>I am new to Jersey Java REST WebService framework. I am trying to write a service method which consumes and produces JSON. My service code is below. It is simplest code, just for studying purpose. </p>
  
  <pre><code>@Path("/myresource")
  public class MyResource {
  
      @Path("/sendReceiveJson")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public String sendReceiveJson(String name)
      {
          System.out.println("Value in name: " + name);
          return "{\"serviceName\": \"Mr.Server\"}";
      }
  
  }
  </code></pre>
  
  <p>And following is JerseyClient code. </p>
  
  <pre><code>public class Program {
      public static void main(String[] args) throws Exception{
  
          String urlString="http://localhost:8080/MyWebService/webresources/myresource/sendReceiveJson";
  
          URL url=new URL(urlString);
          URLConnection connection=url.openConnection();
          connection.setDoOutput(true);
          OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
          out.write("{\"clientName\": \"Mr.Client\"}");
          out.close();
  
          BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
          String decodedString;
          while ((decodedString = in.readLine()) != null) {
          System.out.println(decodedString);
          }
          in.close();
  }
  }
  </code></pre>
  
  <p>But when i run service and then client, i am unable to send/receive JSON data. I get Exception at <code>connection.getInputStream()</code> which is </p>
  
  <pre><code>Server returned HTTP response code: 405 for URL: http://localhost:8080/hellointernet/webresources/myresource/sendReceiveJson
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1625)
  </code></pre>
  
  <p>Please guide me, what needs to correct, or whether i am in wrong direction. </p>