aboutsummaryrefslogtreecommitdiffstats
path: root/gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java')
-rw-r--r--gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java37
1 files changed, 2 insertions, 35 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java b/gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java
index 49a7d25d..895b9de6 100644
--- a/gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java
+++ b/gson/src/main/java/org/onap/policy/common/gson/OffsetTimeTypeAdapter.java
@@ -20,49 +20,16 @@
package org.onap.policy.common.gson;
-import com.google.gson.JsonParseException;
-import com.google.gson.TypeAdapter;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonToken;
-import com.google.gson.stream.JsonWriter;
-import java.io.IOException;
import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeParseException;
-public class OffsetTimeTypeAdapter extends TypeAdapter<OffsetTime> {
- private DateTimeFormatter formatter;
+public class OffsetTimeTypeAdapter extends StringTypeAdapter<OffsetTime> {
public OffsetTimeTypeAdapter() {
this(DateTimeFormatter.ISO_OFFSET_TIME);
}
public OffsetTimeTypeAdapter(DateTimeFormatter formatter) {
- this.formatter = formatter;
- }
-
- @Override
- public OffsetTime read(JsonReader in) throws IOException {
- try {
- if (in.peek() == JsonToken.NULL) {
- in.nextNull();
- return null;
- } else {
- return OffsetTime.parse(in.nextString(), formatter);
- }
-
- } catch (DateTimeParseException e) {
- throw new JsonParseException("invalid time", e);
- }
- }
-
- @Override
- public void write(JsonWriter out, OffsetTime value) throws IOException {
- if (value == null) {
- out.nullValue();
- } else {
- String text = value.format(formatter);
- out.value(text);
- }
+ super("time", string -> OffsetTime.parse(string, formatter), value -> value.format(formatter));
}
}