title: Moshi Custom Adapter isn't being called
body: <h1>TL;DR:</h1>
  
  <p>My questions are:</p>
  
  <p><strong>1 - How can I make an <code>Adapter</code> for the <code>"timestamp": 1515375392.225</code> to <code>ZonedDateTime</code>.</strong></p>
  
  <p><strong>2 - How can I register the <code>List&lt;Report&gt;</code> adapter in the <code>moshi</code> object <code>Builder</code> if I need the moshi object to get this adapter, according to the <a href="https://github.com/square/moshi#parse-json-arrays" rel="nofollow noreferrer">documentation</a>?</strong></p>
  
  <hr>
  
  <p>My JSON string has the following structure:</p>
  
  <pre><code>[
    {
      "id": 0,
      "location": {
        "latitude": -22.967049,
        "longitude": -43.19096
      },
      "timestamp": 1515375392.225
    },
    {
      "id": 0,
      "location": {
        "latitude": -22.965845,
        "longitude": -43.191102
      },
      "timestamp": 1515375392.225
    },
  .......
  }]
  </code></pre>
  
  <p>The <code>timestamp</code> is an automatic conversion made by the <code>Jackson</code> <a href="https://github.com/FasterXML/jackson-modules-java8/tree/master/datetime" rel="nofollow noreferrer"><code>JavaTimeModule</code></a>, it converts a <code>ZonedDateTime</code> to a <code>timestamp String</code> in the form of a decimal number representing the <code>seconds</code> and <code>nanoseconds</code> from an <code>Instant</code>.</p>
  
  <p>In order to parse the JSON <code>timestamp String</code>, I made the following <code>Moshi</code> adapter:</p>
  
  <pre><code>public class ZonedDateTimeAdapter {
      @FromJson ZonedDateTime fromJson(String timestamp) {
          int decimalIndex = timestamp.indexOf('.');
          long seconds = Long.parseLong(timestamp.substring(0, decimalIndex));
          long nanoseconds = Long.parseLong(timestamp.substring(decimalIndex));
  
          return Instant.ofEpochSecond(seconds, nanoseconds).atZone(ZoneId.systemDefault());
      }
  
      @ToJson String toJson(ZonedDateTime zonedDateTime) {
          Instant instant = zonedDateTime.toInstant();
          return instant.getEpochSecond() + "." + instant.getNano();
      }
  }
  </code></pre>
  
  <p>And then I register this adapter as:</p>
  
  <pre><code>Type type = Types.newParameterizedType(List.class, Report.class);
  
  Moshi moshi = new Moshi.Builder().add(new ZonedDateTimeAdapter()).build();
  JsonAdapter&lt;List&lt;Report&gt;&gt; reportAdapter = moshi.adapter(type);
  
  retrofit = new Retrofit.Builder()
                         .baseUrl(BASE_URL)
                         .addConverterFactory(MoshiConverterFactory.create(moshi))
                         .build();
  </code></pre>
  
  <p>The problem is, when I call my webservice using <code>Retrofit</code>, I get the following <code>Exception</code>:</p>
  
  <blockquote>
    <p>com.squareup.moshi.JsonDataException: java.lang.NumberFormatException:
    For input string: ".067000000" at $[0].timestamp</p>
  </blockquote>
  
  <p><em>(keep in mind the nanoseconds .067000000 here won't be the same as the JSON example that I gave before, since they called the webservice at different times).</em></p>
  
  <p>I tried to place a breakpoint on my <code>ZonedDateTimeAdapter</code>, but it's never being called. But it's influencing Moshi, because if I remove it from the <code>Moshi.Builder</code>, the error changes to:</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException: Cannot serialize
    abstract class org.threeten.bp.ZoneId</p>
  </blockquote>
  
  <p>I also tried to change the <code>ZonedDateTimeAdapter</code> to deal with <code>Double</code> instead of <code>String</code>, but it just changes the error message to:</p>
  
  <blockquote>
    <p>com.squareup.moshi.JsonDataException: java.lang.NumberFormatException:
    For input string: ".515376840747E9" at $[0].timestamp</p>
  </blockquote>
  
  <p>So, basically, I have a bunch of changing error messages and no idea what am I doing wrong. I followed the Moshi documentation on <code>Custom Adapters</code> and I don't know what else to do.</p>