title: Post request in json RESTful
body: <p>I want to do a POST operation in a server using java.</p>
  
  <p>It is working with xml but not with json. Can you help me?
  This example works good.</p>
  
  <pre><code>config = new ClientConfig();
  client = ClientBuilder.newClient(config);
  target = client.target("http://192.168.1.156:5700/sdelab07-local").path("person");
  
  String xmlRequest = "&lt;person&gt;&lt;firstname&gt;ffff&lt;/firstname&gt;&lt;healthProfile&gt;&lt;value&gt;89&lt;/value&gt;&lt;/healthProfile&gt;&lt;/person&gt;";
  
  response = target.request(MediaType.APPLICATION_XML_TYPE).post(Entity.xml(xmlRequest));
  String xmlLine = response.readEntity(String.class);
  System.out.println(xmlLine);
  </code></pre>
  
  <p>This POST request with json does not work good, why?</p>
  
  <pre><code>String jsonRequest = "{\"firstname\" : \"ffff\"," +
                              "\"healthProfile\" : {" +
                              "\"value\" : 51}}";
  
  response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(jsonRequest));
  String jsonLine = response.readEntity(String.class);
  System.out.println(jsonLine);
  </code></pre>
  
  <p>I get the following error: </p>
  
  <blockquote>
    <p>N/A (through reference chain: introsde.rest.ehealth.model.Person["healthProfile"])</p>
  </blockquote>
  
  <p>I think my jsonRequest is in a wrong format. If so, how should be the right one?</p>
  
  <p>I tried to make a post request in Postman now. Id does not work even there. I do not have problems on posting using xml.
  With json I get the following message (in Postman):</p>
  
  <blockquote>
    <p>Can not deserialize instance of introsde.rest.ehealth.model.LifeStatus
    out of START_ARRAY token  at [Source:
    org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@208dd233;
    line: 5, column: 31] (through reference chain:
    introsde.rest.ehealth.model.Person["healthProfile"])</p>
  </blockquote>
  
  <p>This is my Person class:</p>
  
  <pre><code>&gt; @Entity  // indicates that this class is an entity to persist in DB
  &gt; @Table(name="Person") // to whole table must be persisted 
  &gt; @NamedQuery(name="Person.findAll", query="SELECT p FROM Person p")
  &gt; @XmlType(propOrder={"idPerson",  "name", "lastname", "birthdate",
  &gt; "email", "username", "lifeStatus"}) @XmlRootElement
  &gt; 
  &gt; public class Person implements Serializable {
  &gt;     private static final long serialVersionUID = 1L;
  &gt;     @Id // defines this attributed as the one that identifies the entity
  &gt;     @GeneratedValue(generator="sqlite_person")
  &gt;     @TableGenerator(name="sqlite_person", table="sqlite_sequence",
  &gt;         pkColumnName="name", valueColumnName="seq",
  &gt;         pkColumnValue="Person")
  &gt;     @Column(name="idPerson")
  &gt;     private int idPerson;
  &gt;     @Column(name="lastname")
  &gt;     private String lastname;
  &gt;     @Column(name="name")
  &gt;     private String name;
  &gt;     @Column(name="username")
  &gt;     private String username;
  &gt;     //@Temporal(TemporalType.DATE) // defines the precision of the date attribute
  &gt;     @Column(name="birthdate")
  &gt;     private String birthdate; 
  &gt;     @Column(name="email")
  &gt;     private String email;
  &gt;     
  &gt;     // mappedBy must be equal to the name of the attribute in healthProfile that maps this relation
  &gt;     @XmlElement(name="healthProfile")
  &gt;     @OneToMany(mappedBy="person",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
  &gt;     private List&lt;LifeStatus&gt; lifeStatus;
  &gt;     
  &gt;     //@XmlElementWrapper(name = "Measurements")
  &gt;     //@XmlElement(name="lifeStatus")
  &gt;     public List&lt;LifeStatus&gt; getLifeStatus() {
  &gt;         return lifeStatus;
  &gt;     }
  &gt;     
  &gt;     public void setLifeStatus(LifeStatus newLS){
  &gt;       this.lifeStatus.add(newLS);
  &gt;     }
  &gt;     
  &gt;     // mappedBy must be equal to the name of the attribute in HealthMeasureHistory that maps this relation
  &gt;     @OneToMany(mappedBy="person",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
  &gt;     private List&lt;HealthMeasureHistory&gt; healthMeasureHistory;
  &gt;     
  &gt;     //@XmlElementWrapper(name = "measureHistory")
  &gt;     //@XmlElement(name = "measure")
  &gt;     @XmlTransient
  &gt;     public List&lt;HealthMeasureHistory&gt; getHealthMeasureHistories() {
  &gt;         return healthMeasureHistory;
  &gt;     }
  &gt;    
  &gt;     
  &gt;     
  &gt;     // add below all the getters and setters of all the private attributes
  &gt;     public Person() {}
  &gt;     // getters
  &gt;     //@XmlTransient
  &gt;     public int getIdPerson(){
  &gt;         return idPerson;
  &gt;     }
  &gt; 
  &gt;     public String getLastname(){
  &gt;         return lastname;
  &gt;     }
  &gt;     
  &gt;     @XmlElement(name="firstname")
  &gt;     public String getName(){
  &gt;         return name;
  &gt;     }
  &gt;     public String getUsername(){
  &gt;         return username;
  &gt;     }
  &gt;     public String getBirthdate(){
  &gt;         return birthdate;
  &gt;     }
  &gt;     public String getEmail(){
  &gt;         return email;
  &gt;     }
  &gt;     
  &gt;     // setters
  &gt;     public void setIdPerson(int idPerson){
  &gt;         this.idPerson = idPerson;
  &gt;     }
  &gt;     public void setLastname(String lastname){
  &gt;         this.lastname = lastname;
  &gt;     }
  &gt;     public void setName(String name){
  &gt;         this.name = name;
  &gt;     }
  &gt;     public void setUsername(String username){
  &gt;         this.username = username;
  &gt;     }
  &gt;     public void setBirthdate(String birthdate){
  &gt;         this.birthdate = birthdate;
  &gt;     }
  &gt;     public void setEmail(String email){
  &gt;         this.email = email;
  &gt;     }
  &gt; 
  &gt;     
  &gt;     public static Person getPersonById(int personId) {
  &gt;         EntityManager em = LifeCoachDao.instance.createEntityManager();
  &gt;         Person p = em.find(Person.class, personId);
  &gt;         LifeCoachDao.instance.closeConnections(em);
  &gt;         return p;
  &gt;     }
  &gt; 
  &gt;     public static List&lt;Person&gt; getAll() {
  &gt;         EntityManager em = LifeCoachDao.instance.createEntityManager();
  &gt;         List&lt;Person&gt; list = em.createNamedQuery("Person.findAll", Person.class)
  &gt;             .getResultList();
  &gt;         LifeCoachDao.instance.closeConnections(em);
  &gt;         return list;
  &gt;     }
  &gt; 
  &gt;     public static Person savePerson(Person p) {
  &gt;         EntityManager em = LifeCoachDao.instance.createEntityManager();
  &gt;         EntityTransaction tx = em.getTransaction();
  &gt;         tx.begin();
  &gt;         em.persist(p);
  &gt;         tx.commit();
  &gt;         LifeCoachDao.instance.closeConnections(em);
  &gt;         return p;
  &gt;     } 
  &gt;     
  &gt;     public static Person savePersonWithDetail(Person p) {
  &gt;         EntityManager em = LifeCoachDao.instance.createEntityManager();
  &gt;         EntityTransaction tx = em.getTransaction();
  &gt;         tx.begin();
  &gt;         em.persist(p);
  &gt;         tx.commit();
  &gt;         LifeCoachDao.instance.closeConnections(em);
  &gt;         return p;
  &gt;     }
  &gt; 
  &gt;     public static Person updatePerson(Person p) {
  &gt;         EntityManager em = LifeCoachDao.instance.createEntityManager(); 
  &gt;         EntityTransaction tx = em.getTransaction();
  &gt;         tx.begin();
  &gt;         p=em.merge(p);
  &gt;         tx.commit();
  &gt;         LifeCoachDao.instance.closeConnections(em);
  &gt;         return p;
  &gt;     }
  &gt; 
  &gt;     public static void removePerson(Person p) {
  &gt;         EntityManager em = LifeCoachDao.instance.createEntityManager();
  &gt;         EntityTransaction tx = em.getTransaction();
  &gt;         tx.begin();
  &gt;         p=em.merge(p);
  &gt;         em.remove(p);
  &gt;         tx.commit();
  &gt;         LifeCoachDao.instance.closeConnections(em);
  &gt;     }
  &gt;      }
  </code></pre>
  
  <p>Thank you so much!</p>