title: Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
body: <p>I've just tried to calling <code>index.jsp</code> which sends a json to my rest project with http POST.</p>
  <p>But it throws me this error: <br>
  I can't figure out where is the issue
  Any tip? I haven't idea for this.</p>
  <blockquote>
  <p>org.apache.catalina.core.StandardWrapperValve invoke
  GRAVE: Servlet.service() for servlet [jersey-serlvet] in context with path [/HibernateTutorialWeb] threw exception [org.codehaus.jackson.JsonParseException: Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
  at [Source: org.apache.catalina.connector.CoyoteInputStream@24097548; line: 1, column: 2]] with root cause
  org.codehaus.jackson.JsonParseException: Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
  at [Source: org.apache.catalina.connector.CoyoteInputStream@24097548; line: 1, column: 2]
  at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1213)
  at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:375)
  at org.codehaus.jackson.impl.JsonParserMinimalBase._reportUnexpectedChar(JsonParserMinimalBase.java:306)
  at org.codehaus.jackson.impl.Utf8StreamParser._handleUnexpectedValue(Utf8StreamParser.java:1536)
  at org.codehaus.jackson.impl.Utf8StreamParser._nextTokenNotInObject(Utf8StreamParser.java:432)
  at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:318)
  at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2168)
  at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
  at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
  at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
  at com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
  at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
  at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
  at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
  at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
  at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
  at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
  at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
  at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
  at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
  at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
  at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
  at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
  at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
  at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Unknown Source)</p>
  </blockquote>
  <p><strong>index.jsp</strong>:</p>
  <pre><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
          &lt;title&gt;Send jSon - put method&lt;/title&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
      &lt;script&gt;
      //var people = {&quot;address&quot;: &quot;Address 12&quot;, &quot;name&quot;: &quot;twelve&quot;, &quot;id&quot;: 12,&quot;surname&quot;: &quot;twelve&quot;};
      var people={&quot;address&quot;: &quot;hello&quot;};
      function sendobject(){
        $.ajax({
              type: &quot;POST&quot;,
              url: &quot;http://localhost:8080/HibernateTutorialWeb/rest/person/post&quot;,
              data: people,
              contentType: &quot;application/json; charset=utf-8&quot;,
              dataType: &quot;json&quot;,
              success: function(data){alert(data);},
              failure: function(errMsg) {
                  alert(errMsg);
              }
        });
      }
      &lt;/script&gt;
          &lt;input type=&quot;button&quot; onclick=&quot;sendobject()&quot; value=&quot;invia&quot;&gt; &lt;/input&gt;
          &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/&lt;html&gt;
  </code></pre>
  <p><strong>PersonService . java</strong></p>
  <pre><code>package com.ws.service;
  
  import java.util.List;
  
  import javax.ws.rs.*;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import javax.ws.rs.core.Response.ResponseBuilder;
  
  import com.dao.*;
  import com.model.*;
  
  @Path(&quot;/person&quot;)
  public class PersonService {
  
      // try hello data
      // http://localhost:8080/HibernateTutorialWeb/rest/person/hello/mario
      @GET
      @Path(&quot;/hello/{param}&quot;)
      public Response getMsg(@PathParam(&quot;param&quot;) String msg) {
  
          String output = &quot;Jersey say hello : &quot; + msg;
  
          return Response.status(200).entity(output).build();
      }
  
      // http://localhost:8080/HibernateTutorialWeb/rest/person/2
      @GET
      @Path(&quot;{id}&quot;)
      @Produces(MediaType.APPLICATION_JSON)
      public Person getPersonById(@PathParam(&quot;id&quot;) int id) {
          return new PersonDao().getPersonById(id);
          // error for type of response incorrect
          /*
           * public ResponseBuilder getPersonById(@PathParam(&quot;id&quot;) int id){
           * PersonDao pDao = new PersonDao (); if(pDao.getPersonById(id) != null)
           * {return Response.status(200).entity(new
           * PersonDao().getPersonById(id));} else{ return
           * Response.status(200).entity(&quot;Utente id: &quot;+ id + &quot;, Rimosso&quot;); }
           */
      }
  
      // //http://localhost:8080/HibernateTutorialWeb/rest/person/getAllJson
      @GET
      @Path(&quot;/getAllJson&quot;)
      @Produces(MediaType.APPLICATION_JSON)
      public List&lt;Person&gt; getAllJson() {
          return new PersonDao().getAllPerson();
      }
  
      @GET
      @Path(&quot;/xml/{id}&quot;)
      @Produces(MediaType.APPLICATION_XML)
      public Person getPersonByIdXML(@PathParam(&quot;id&quot;) int id) {
          return new PersonDao().getPersonById(id);
      }
  
      @POST
      @Path(&quot;/post&quot;)
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public Response createUtenteJSON(Person person) {
          new PersonDao().saveOrUpdate(person);
          String result = &quot;Person saved : &quot; + person;
          return Response.status(201).entity(result).build();
      }
  
      @PUT
      @Consumes(MediaType.APPLICATION_JSON)
      public Response updateUtente(Person person) {
          if (person.getId() != 0) {
              new PersonDao().saveOrUpdate(person);
              return Response.ok(person, MediaType.APPLICATION_JSON).build();
          } else {
              return Response.status(Response.Status.BAD_REQUEST)
                      .entity(&quot;Specificare l'id dell'utente&quot;).build();
          }
      }
  
      @DELETE
      @Path(&quot;{id}&quot;)
      public Response removePerson(@PathParam(&quot;id&quot;) Integer id) {
          new PersonDao().deletePerson(id);
          return Response.status(200).entity(&quot;Utente id: &quot; + id + &quot;, Rimosso&quot;)
                  .build();
      }
  
  }
  </code></pre>
  <p><strong>PersonDao.java</strong></p>
  <pre><code>package com.dao;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.Transaction;
  
  import com.model.Person;
  import com.util.SessionFactoryUtil;
  
  public class PersonDao {
  
      public void saveOrUpdate(Person person) {
          Transaction trns = null;
          Session session = SessionFactoryUtil.getSessionFactory().openSession();
  
          try {
              trns = session.beginTransaction();
              if (person.getId() != 0) {
                  //if exists update obj
                  session.update(person);
              } else {
                  session.save(person);
              }
              session.getTransaction().commit();
          } catch (RuntimeException e) {
              if (trns != null) {
                  trns.rollback();
              }
              e.printStackTrace();
          } finally {
              session.flush();
              session.close();
          }
      }
  
      public void deletePerson(int id) {
          Transaction trns = null;
          Session session = SessionFactoryUtil.getSessionFactory().openSession();
          try {
              trns = session.beginTransaction();
              Person person = (Person) session.load(Person.class, new Integer(id));
              
              System.out.println(&quot;Deleted person :&quot;+person.toString());
              
              session.delete(person);
              
              session.getTransaction().commit();
          } catch (RuntimeException e) {
              if (trns != null) {
                  trns.rollback();
              }
              e.printStackTrace();
          } finally {
              session.flush();
              session.close();
          }
  
      }
  
      public List&lt;Person&gt; getAllPerson() {
          List&lt;Person&gt; people = new ArrayList&lt;Person&gt;();
          Transaction trns = null;
          Session session = SessionFactoryUtil.getSessionFactory().openSession();
          try {
              trns = session.beginTransaction();
              people = session.createQuery(&quot;from Person&quot;).list();
              
              //session.getTransaction().commit();
          } catch (RuntimeException e) {
              if (trns != null) {
                  trns.rollback();
              }
          } finally {
              session.flush();
              session.close();
          }
          System.out.println(&quot;People list : \n&quot;);
          for(int i=0;i&lt;people.size();i++){
              System.out.println(people.get(i));
          }
          return people;
      }
  
      public Person getPersonById(int id) {
          Person person = null;
          Transaction trns = null;
          Session session = SessionFactoryUtil.getSessionFactory().openSession();
          try {
              trns = session.beginTransaction();
              String queryString = &quot;FROM Person WHERE id = :id&quot;;
              Query query = session.createQuery(queryString);
              query.setInteger(&quot;id&quot;, id);
              person = (Person) query.uniqueResult();
          } catch (RuntimeException e) {
              e.printStackTrace();
          } finally {
              session.flush();
              session.close();
          }
          return person;
      }
  
  }
  </code></pre>
  <p><strong>Updated :</strong>
  on index.jsp
  <br></p>
  <pre><code>var people = JSON.parse({&quot;address&quot;: &quot;Indirizzo 12&quot;, &quot;name&quot;: &quot;dodici&quot;, &quot;id&quot;: 12,&quot;surname&quot;: &quot;dodici&quot;});
  </code></pre>
  <p>Now the error is this :</p>
  <pre><code>    HTTP Status 500 - java.io.EOFException: No content to map to Object due to end of input
  
  type Exception report
  
  message java.io.EOFException: No content to map to Object due to end of input
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  javax.servlet.ServletException: java.io.EOFException: No content to map to Object due to end of input
      com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  root cause
  
  java.io.EOFException: No content to map to Object due to end of input
      org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2173)
      org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2106)
      org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1004)
      org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
      com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
      com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
      com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
      com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
      com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
      com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
      com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
      com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
      com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
      com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
      com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
      com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
      com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
      com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
      com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
      com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>