title: Java 8 LocalDateTime Deserialization using gson
body: <p>I want to deserialize a json String containing LocalDateTime fields in to a class using gson.</p>
  
  <p>But this throws nullpointer exceptions.</p>
  
  <p>My JSON:</p>
  
  <pre><code>metrics": {
  "measurements": [
  {
  "serviceName": "myService",
  "start": {
  "year": 2018,
  "month": "APRIL",
  "dayOfMonth": 26,
  "dayOfWeek": "THURSDAY",
  "dayOfYear": 116,
  "monthValue": 4,
  "hour": 18,
  "minute": 53,
  "second": 51,
  "nano": 243000000,
  "chronology": {
  "id": "ISO",
  "calendarType": "iso8601"
  }
  },
  "stop": {
  "year": 2018,
  "month": "APRIL",
  "dayOfMonth": 26,
  "dayOfWeek": "THURSDAY",
  "dayOfYear": 116,
  "monthValue": 4,
  "hour": 18,
  "minute": 53,
  "second": 51,
  "nano": 841000000,
  "chronology": {
  "id": "ISO",
  "calendarType": "iso8601"
  }
  },
  "processingTime": 598
  }
  </code></pre>
  
  <p>The code i use to get my object:</p>
  
  <pre><code>Metrics metrics = gson.fromJson(jsonString, Metrics.class);
  </code></pre>
  
  <p>But gson is only able to deserialize the processingTime field of my object.</p>
  
  <p>I've tried this too:</p>
  
  <p><a href="https://stackoverflow.com/questions/22310143/java-8-localdatetime-deserialized-using-gson">Java 8 LocalDateTime deserialized using Gson</a></p>
  
  <p>but this results in </p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: This is not a JSON Primitive.
      at com.google.gson.JsonElement.getAsJsonPrimitive(JsonElement.java:122)
      at com.foo.config.AppConfig.lambda$gson$1(AppConfig.java:63)
  </code></pre>
  
  <p>any thoughts? </p>
  
  <p>Thanks</p>