title: Cannot Parse a JSON response that is received by RestTemplate
body: <p>I need to parse a JSON response that I receive from a web service but I am receiving following error message, I puzzled with the this. I tried it without Results class as well to no avail. Any help would be appreciated.</p>
  
  <blockquote>
    <p>The request sent by the client was syntactically incorrect.</p>
  </blockquote>
  
  <p><strong>Code</strong></p>
  
  <pre><code>RestTemplate restTemplate = new RestTemplate();
  restTemplate.getMessageConverters().add(new 
                                          MappingJackson2HttpMessageConverter());
          ResponseEntity&lt;Results&gt; responseEntity = restTemplate
                  .getForEntity(
                          "http://primesport.sieenasoftware.com/QryApi
                           /GetEvents?
                           username=username&amp;
                           password=password&amp;
                           userid=23",
                           Results.class);
          System.err.println("&gt;&gt;" + responseEntity.getBody().getEvents().size());
  </code></pre>
  
  <p><strong>Classes</strong></p>
  
  <p><strong>Results</strong></p>
  
  <pre><code>public class Results {
      private List&lt;Events&gt; events;
      getter and setter
  }
  </code></pre>
  
  <p><strong>Events</strong></p>
  
  <pre><code>   public class Event {
         private long eventId;
         private String name;
         private String subTitle;
         private String description;
         private String localDate;
         private String localDateFrom;
         private String imageUrl;
         private int venueId;
         private String venue;
         private int availableTickets;
         private long performerId;
         private String performer;
         private String performerType;
         private int subcategoryId;
         private String urlCategoryName;
         private String metaTitle;
         private String metaDescription;
         private String primeSportUrl;
         private String sectionWiseView;
         private String venueCity;
         private String venueState;
         private String snippetDate;
         private int eiProductionId;
         private boolean requireBillingAsShipping;
      public long getEventId() {
          return eventId;
      }
      public void setEventId(long eventId) {
          this.eventId = eventId;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public String getSubTitle() {
          return subTitle;
      }
      public void setSubTitle(String subTitle) {
          this.subTitle = subTitle;
      }
      public String getDescription() {
          return description;
      }
      public void setDescription(String description) {
          this.description = description;
      }
      public String getLocalDate() {
          return localDate;
      }
      public void setLocalDate(String localDate) {
          this.localDate = localDate;
      }
      public String getLocalDateFrom() {
          return localDateFrom;
      }
      public void setLocalDateFrom(String localDateFrom) {
          this.localDateFrom = localDateFrom;
      }
      public String getImageUrl() {
          return imageUrl;
      }
      public void setImageUrl(String imageUrl) {
          this.imageUrl = imageUrl;
      }
      public int getVenueId() {
          return venueId;
      }
      public void setVenueId(int venueId) {
          this.venueId = venueId;
      }
      public String getVenue() {
          return venue;
      }
      public void setVenue(String venue) {
          this.venue = venue;
      }
      public int getAvailableTickets() {
          return availableTickets;
      }
      public void setAvailableTickets(int availableTickets) {
          this.availableTickets = availableTickets;
      }
      public long getPerformerId() {
          return performerId;
      }
      public void setPerformerId(long performerId) {
          this.performerId = performerId;
      }
      public String getPerformer() {
          return performer;
      }
      public void setPerformer(String performer) {
          this.performer = performer;
      }
      public String getPerformerType() {
          return performerType;
      }
      public void setPerformerType(String performerType) {
          this.performerType = performerType;
      }
      public int getSubcategoryId() {
          return subcategoryId;
      }
      public void setSubcategoryId(int subcategoryId) {
          this.subcategoryId = subcategoryId;
      }
      public String getUrlCategoryName() {
          return urlCategoryName;
      }
      public void setUrlCategoryName(String urlCategoryName) {
          this.urlCategoryName = urlCategoryName;
      }
      public String getMetaTitle() {
          return metaTitle;
      }
      public void setMetaTitle(String metaTitle) {
          this.metaTitle = metaTitle;
      }
      public String getMetaDescription() {
          return metaDescription;
      }
      public void setMetaDescription(String metaDescription) {
          this.metaDescription = metaDescription;
      }
      public String getPrimeSportUrl() {
          return primeSportUrl;
      }
      public void setPrimeSportUrl(String primeSportUrl) {
          this.primeSportUrl = primeSportUrl;
      }
      public String getSectionWiseView() {
          return sectionWiseView;
      }
      public void setSectionWiseView(String sectionWiseView) {
          this.sectionWiseView = sectionWiseView;
      }
      public String getVenueCity() {
          return venueCity;
      }
      public void setVenueCity(String venueCity) {
          this.venueCity = venueCity;
      }
      public String getVenueState() {
          return venueState;
      }
      public void setVenueState(String venueState) {
          this.venueState = venueState;
      }
      public String getSnippetDate() {
          return snippetDate;
      }
      public void setSnippetDate(String snippetDate) {
          this.snippetDate = snippetDate;
      }
      public int getEiProductionId() {
          return eiProductionId;
      }
      public void setEiProductionId(int eiProductionId) {
          this.eiProductionId = eiProductionId;
      }
      public boolean isRequireBillingAsShipping() {
          return requireBillingAsShipping;
      }
      public void setRequireBillingAsShipping(boolean requireBillingAsShipping) {
          this.requireBillingAsShipping = requireBillingAsShipping;
      }
  
  }
  </code></pre>
  
  <p><strong>Partial Response</strong></p>
  
  <pre><code>[{
  "EventId":1000250537,
  "Name":"US Open Golf",
  "SubTitle":null,
  "Description":"US Open Golf Tickets",
  "Date":"\/Date(1434873560000)\/",
  "LocalDate":"6/20/2015 11:59 PM",
  "LocalDateFrom":null,
  "ImageUrl":null,
  "VenueId":146566,
  "Venue":"Chambers Bay Golf Course",
  "AvailableTickets":33,
  "PerformerId":151551,
  "Performer":"US Open Golf",
  "PerformerType":"Golf",
  "SubcategoryId":55,
  "UrlCategoryName":"Sports",
  "MetaTitle":null,
  "MetaDescription":null,
  "PrimeSportUrl":"http://primesport.sieenasoftware.com/e/sports/us-open-golf/chambers-bay-golf-course/",
  "SectionWiseView":null,
  "VenueCity":"UNIVERSITY PLACE",
  "VenueState":"WA",
  "SnippetDate":null,
  "EIProductionId":99985,
  "RequireBillingAsShipping":false},
  {
  "EventId":1000253479,
  "Name":"Womens College World Series",
  "SubTitle":null,
  "Description": .....
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I know JAXB can be used for both JSON and XML, I am trying to use it to see if it would help to solve the issue.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The code is returning following exception:</p>
  
  <pre><code>    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of com.myproject.myevent.Results out of START_ARRAY token
   at [Source: java.io.PushbackInputStream@dedcd10; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.myproject.myevent.Results out of START_ARRAY token
   at [Source: java.io.PushbackInputStream@dedcd10; line: 1, column: 1]
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:208)
      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:200)
      at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:97)
      at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:809)
      at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:793)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:576)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:529)
      at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:261)
      at com.myproject.service.TicketSeviceImpl.primeSport(TicketSeviceImpl.java:217)
      at com.myproject.service.TicketSeviceImpl.findTicket(TicketSeviceImpl.java:45)
      at com.myproject.web.TicketController.findTicket(TicketController.java:29)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>following code returns </p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>try {
              System.err.println("&gt;&gt;&gt; primeSport");
              RestTemplate restTemplate = new RestTemplate();
              restTemplate.getMessageConverters().add(
                      new MappingJackson2HttpMessageConverter());
              ResponseEntity&lt;Event[]&gt; responseEntity = restTemplate
                      .getForEntity(
                              "http://primesport.sieenasoftware.com/QryApi/GetEvents?username=username&amp;password=password&amp;userid=23",
                              Event[].class);
              System.err.println("&gt;&gt;" + responseEntity.getBody().length);
              System.err.println("&gt;&gt;" + responseEntity.getBody()[0].getEventId());
              System.err.println("&gt;&gt;" + responseEntity.getBody()[1].getEventId());
          } catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>&gt;1532
  &gt;0
  &gt;0
  </code></pre>