title: Android GSON Retrofit Serializing JSON Date string to java.util.date
body: <p>I'm relatively new to Android dev, coming from an iOS background. Trying to parse my JSON response into a Date object using Retrofit and GSON.</p>
  <p>I tried this way with no luck: <a href="https://stackoverflow.com/questions/18473011/retrofit-gson-serialize-date-from-json-string-into-java-util-date">Retrofit GSON serialize Date from json string into java.util.date</a></p>
  <p>Now ,  am collecting the response and assigning objects when they are strings correctly, as expected. However when it is a date object the following error is given.</p>
  <blockquote>
  <p>com.google.gson.JsonSyntaxException: 20170502T000000</p>
  <p>java.text.ParseException: Failed to parse date [&quot;20170502T000000']: No
  time zone indicator</p>
  </blockquote>
  <p>I've found a number of different similar questions and answers online, however none seem to do the trick.</p>
  <p>MWE of JSON Response</p>
  <pre><code>{
      &quot;EventDate&quot;: &quot;20170502T000000&quot;
  }
  </code></pre>
  <p>JSON Deserializer Class</p>
  <pre><code>import com.google.gson.JsonDeserializationContext;
  import com.google.gson.JsonDeserializer;
  import com.google.gson.JsonElement;
  import com.google.gson.JsonParseException;
  
  import java.lang.reflect.Type;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.TimeZone;
  
  public class DateDeserializer implements JsonDeserializer&lt;Date&gt; {
  
      @Override
      public Date deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
          String date = element.getAsString();
  
          SimpleDateFormat format = new
          SimpleDateFormat(&quot;yyyyMMdd'T'HHmmss&quot;);
          format.setTimeZone(TimeZone.getTimeZone(&quot;GMT&quot;));
          try {
              return format.parse(date);
          } catch (ParseException exp) {
              return null;
          }
      }
  }
  </code></pre>
  <p>GSON Builder</p>
  <pre><code>public static final Retrofit retrofit = new Retrofit.Builder()
          .baseUrl(&quot;http://uat.api.net/&quot;)
          .addConverterFactory(GsonConverterFactory.create(
                  new GsonBuilder()
                          .registerTypeAdapter(Date.class, new DateDeserializer())
                          .create()
                  )
          )
          .build();
  </code></pre>
  <p>I've tried to add the 'Z' or Z to the end of the date formatter although it shouldn't matter in this case because the date in the JSON doesn't show a timezone.</p>
  <p>Any help would be greatly appreciated</p>