title: jax-rs response.getEntity not working
body: <p>I want to use javax.ws.rs.core.Response to send and receive an Card entity object. But I don't know how to convert the contents back in to a Card object.</p>
  
  <p>My testCreate() method should execute the create(Card card) method, receive back the json and convert it in to a card object. But I somehow always get type mismatches or it says that the getEntity() method can't be executed like this: response.getEntity(Card.class).</p>
  
  <p>Does anybody know how I have to handle the response correctly so that I can convert the returned json entity in to a Card object again?</p>
  
  <p>Here my CardResource method:</p>
  
  <pre><code>@POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response create(Card card) {
      Card c = dao.create(card);
      if(c.equals(null)) {
          return Response.status(Status.BAD_REQUEST).entity("Create failed!").build();
      }
  
      return Response.status(Status.OK)
              .entity(c)
              .type(MediaType.APPLICATION_JSON)
              .build();
  }
  </code></pre>
  
  <p>And here my CardResourceTests class</p>
  
  <pre><code>@Test
  public void testCreate() {
      boolean thrown = false;
      CardResource resource = new CardResource();
  
      Card c = new Card(1, "Cardname", "12345678", 1, 1, 
              "cardname.jpg", new Date(), new Date());        
  
      try {
          Response result = resource.create(c);
          System.out.println(result.getEntity(Card.class)); // not working!!!
          if(result.getStatus() != 200) {
              thrown = true;
          }
      } catch(Exception e) {
          e.printStackTrace();
          thrown = true;          
      }
  
      assertEquals("Result", false, thrown);
  }
  </code></pre>
  
  <p>And here my Card.class</p>
  
  <pre><code>@XmlRootElement
  @PersistenceCapable(detachable="true")
  public class Card {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;
  
  @Persistent
  private Integer id;
  
  @Persistent
  private String name;
  
  @Persistent
  private String code;
  
  @Persistent 
  private Integer cardProviderId; 
  
  @Persistent 
  private Integer codeTypeId;
  
  @Persistent
  private String picturePath;
  
  @Persistent
  private Boolean valid;
  
  @Persistent 
  private Date mobCreationDate;
  
  @Persistent
  private Date mobModificationDate;
  
  @Persistent
  private Date creationDate;  
  
  @Persistent
  private Date modificationDate;
  
  public Card() {
      this.setId(null);
      this.setName(null);
      this.setCode(null);
      this.setCardProviderId(null);       
      this.setCodeTypeId(null);
      this.setPicturePath(null);
      this.setMobCreationDate(null);
      this.setMobModificationDate(null);
      this.setCreationDate(null);
      this.setModificationDate(null);
  }
  
  public Card(Integer id, String name, String code, Integer cardProviderId, 
      Integer codeTypeId, String picturePath,
      Date mobCreationDate, Date mobModificationDate) {
      this.setId(id);
      this.setName(name);
      this.setCode(code);
      this.setCardProviderId(cardProviderId);     
      this.setCodeTypeId(codeTypeId);
      this.setPicturePath(picturePath);
      this.setMobCreationDate(mobCreationDate);
      this.setMobModificationDate(mobModificationDate);
      this.setCreationDate(new Date());
      this.setModificationDate(new Date());
  }
  
  public Key getKey() {
      return key;
  }
  
  public void setKey(Key key) {
      this.key = key;
  }
  
  public Integer getId() {
      return id;
  }
  
  public void setId(Integer id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getCode() {
      return code;
  }
  
  public Integer getCardProviderId() {
      return cardProviderId;
  }
  
  public void setCardProviderId(Integer cardProviderId) {
      this.cardProviderId = cardProviderId;
  }
  
  public void setCode(String code) {
      this.code = code;
  }
  
  public Integer getCodeTypeId() {
      return codeTypeId;
  }
  
  public void setCodeTypeId(Integer codeTypeId) {
      this.codeTypeId = codeTypeId;
  }
  
  public String getPicturePath() {
      return picturePath;
  }
  
  public void setPicturePath(String picturePath) {
      this.picturePath = picturePath;
  }
  
  public Date getCreationDate() {
      return creationDate;
  }
  
  public void setCreationDate(Date creationDate) {
      this.creationDate = creationDate;
  }
  
  public Date getModificationDate() {
      return modificationDate;
  }
  
  public void setModificationDate(Date modificationDate) {
      this.modificationDate = modificationDate;
  }
  
  public Date getMobCreationDate() {
      return mobCreationDate;
  }
  
  public void setMobCreationDate(Date mobCreationDate) {
      this.mobCreationDate = mobCreationDate;
  }
  
  public Date getMobModificationDate() {
      return mobModificationDate;
  }
  
  public void setMobModificationDate(Date mobModificationDate) {
      this.mobModificationDate = mobModificationDate;
  }
  
  public Boolean getValid() {
      return valid;
  }
  
  public void setValid(Boolean valid) {
      this.valid = valid;
  }
  }
  </code></pre>
  
  <p>And here my CardDAO class</p>
  
  <pre><code>public class CardDAO {
  private final static Logger logger = Logger.getLogger(CardDAO.class.getName()); 
  
  public Card create(Card card) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
  
      Card c = new Card(card.getId(), card.getName(), card.getCode(), 
          card.getCardProviderId(), card.getCodeTypeId(), card.getPicturePath(),
          new Date(), new Date());
  
      try {
          pm.makePersistent(c);
      } catch(Exception e) {
          logger.severe("Create failed: " + e.getMessage());
          return null;
      } finally {
          pm.close();
      }
  
      return c;
  }
  }
  </code></pre>