title: how to send json object from REST client using javax.ws.rs.client.WebTarget
body: <p>I have a POJO given below which I want to PUT to the server as JSON or XML.</p>
  
  <p>This is what I have done</p>
  
  <p><strong>CLIENT:</strong></p>
  
  <pre><code>ClientConfig config = new ClientConfig();
  Client client = ClientBuilder.newClient(config);
  WebTarget target = client.target(getBaseURI());
  
  public void putFriend(String uri , Friend friend)
  {
      System.out.println(friend.toString());
  
      target = target.path(some_path).path(uri);
      ClientResponse response =        target.request(MediaType.APPLICATION_JSON).put(Entity.entity(friend,MediaType.APPLICATION_JSON),ClientResponse.class);
  }
  </code></pre>
  
  <p>Examples I found on web were using WebResource.</p>
  
  <p>I don't know how to do using WebTarget. What I have done is taken from some example found on SO but Entity.entity() gives error undefined method entity(friend, String).</p>
  
  <p><strong>POJO</strong></p>
  
  <pre><code>@XmlRootElement
  public class Friend{
  
      private String friendURI;
      private String event;
      private String uri;
  
      String getUri() {
          return uri;
      }
      void setUri(String uri) {
          this.uri = uri;
      }
      String getFriendURI() {
          return friendURI;
      }
      void setFriendURI(String friendURI) {
          this.friendURI = friendURI;
      }
      String getEvent() {
          return event;
      }
      void setEvent(String event) {
          this.event = event;
      }
  public String toString() {
          return "Friend [friendURI=" + friendURI + ", uri=" + uri + ", event=" + event
                   + "]";
  }
  </code></pre>
  
  <p>Please guide how to do this.</p>
  
  <p>Thanks</p>