aboutsummaryrefslogtreecommitdiffstats
path: root/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-02-12 10:06:27 -0500
committerJim Hahn <jrh3@att.com>2021-02-12 10:08:38 -0500
commit564ef19e77b5f8b47fe54822939e806162b7b5fb (patch)
treea8de2616608476b608ee5d1c152f86dd80016d3c /gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java
parenta57710faad56015eb3b69a5ce6f8da235ca146c7 (diff)
Make gson type adapters more generic
Enhanced ZonedDateTime adapter so a date format string can be provided. Simplified InstantAsMillis adapter. Issue-ID: POLICY-2905 Change-Id: Ic4ddba19391b165d6a7528ce18c22541d12324c7 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java')
-rw-r--r--gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java8
1 files changed, 2 insertions, 6 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java b/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java
index 6bcfaac3..c63b03c3 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapter.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@ import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.Instant;
-import java.util.concurrent.TimeUnit;
/**
* GSON Type Adapter for "Instant" fields, that encodes them as milliseconds.
@@ -38,10 +37,7 @@ public class InstantAsMillisTypeAdapter extends TypeAdapter<Instant> {
if (value == null) {
out.nullValue();
} else {
- long epochMillis = TimeUnit.MILLISECONDS.convert(value.getEpochSecond(), TimeUnit.SECONDS);
- long nanoMillis = TimeUnit.MILLISECONDS.convert(value.getNano(), TimeUnit.NANOSECONDS);
- long millis = epochMillis + nanoMillis;
- out.value(millis);
+ out.value(value.toEpochMilli());
}
}