ClientDetailResponseV2 { public static ClientDetailResponseV2 fromClient(Client client) { Optional<ApiDate> lastSeen = Optional.ofNullable(client.getLastSeen()); return new AutoValue_ClientDetailResponseV2( client.getName(), client.getDescription(), nullToEmpty(client.getSpiffeId()), client.getCreatedAt().toEpochSecond(), client.getUpdatedAt().toEpochSecond(), client.getCreatedBy(), client.getUpdatedBy(), lastSeen.map(ApiDate::toEpochSecond) ); } ClientDetailResponseV2(); static ClientDetailResponseV2 fromClient(Client client); @SuppressWarnings("unused") @JsonCreator static ClientDetailResponseV2 fromParts(
      @JsonProperty("name") String name,
      @JsonProperty("description") String description,
      @JsonProperty("spiffeId") String spiffeId,
      @JsonProperty("createdAtSeconds") long createdAtSeconds,
      @JsonProperty("updatedAtSeconds") long updatedAtSeconds,
      @JsonProperty("createdBy") String createdBy,
      @JsonProperty("updatedBy") String updatedBy,
      @JsonProperty("lastSeenSeconds") Optional<Long> lastSeenSeconds); @JsonProperty("name") abstract String name(); @JsonProperty("description") abstract String description(); @JsonProperty("spiffeId") abstract String spiffeId(); @JsonProperty("createdAtSeconds") abstract long createdAtSeconds(); @JsonProperty("updatedAtSeconds") abstract long updatedAtSeconds(); @JsonProperty("createdBy") abstract String createdBy(); @JsonProperty("updatedBy") abstract String updatedBy(); @JsonProperty("lastSeenSeconds") abstract Optional<Long> lastSeenSeconds();  }
@Test public void serializesNullLastSeenCorrectly() throws Exception { ApiDate createdAt = new ApiDate(1343826930); ApiDate updatedAt = new ApiDate(1347246930); Client client = new Client(0, "Client Name", "Client Description", null, createdAt, "creator-user", updatedAt, "updater-user", null, null, true, false ); ClientDetailResponseV2 clientDetailResponse = ClientDetailResponseV2.fromClient(client); assertThat(asJson(clientDetailResponse)) .isEqualTo(jsonFixture("fixtures/v2/clientDetailResponse_LastSeenNull.json")); }