diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-12-02 14:09:03 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-12-02 14:09:03 +0000 |
commit | f46ff1a6e23faeb6cf880d3f865a50ce9cb45bec (patch) | |
tree | 01aa853cb9b230b379e309df898b0ee6f26121d5 /models-interactions | |
parent | 7eeb2e07be6b2d0c47d415c4a1398a2c4e699156 (diff) | |
parent | 67bf799635ec4976b4ae8d91d421e1e66f568bba (diff) |
Merge "Use common LocalDateTimeTypeAdaptor for SO"
Diffstat (limited to 'models-interactions')
-rw-r--r-- | models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/SoLocalDateTimeTypeAdapter.java | 41 |
1 files changed, 4 insertions, 37 deletions
diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/SoLocalDateTimeTypeAdapter.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/SoLocalDateTimeTypeAdapter.java index a0e835ffb..918a3ffba 100644 --- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/SoLocalDateTimeTypeAdapter.java +++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/util/SoLocalDateTimeTypeAdapter.java @@ -20,49 +20,16 @@ package org.onap.policy.so.util; -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.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; - -/* - * TODO: combine the functionality of this adapter with existing LocalDateTimeTypeAdapter and eliminate this class. - */ +import org.onap.policy.common.gson.LocalDateTimeTypeAdapter; /** * GSON Type Adapter for "LocalDateTime" fields, that uses the standard RFC_1123_DATE_TIME * formatter. */ -public class SoLocalDateTimeTypeAdapter extends TypeAdapter<LocalDateTime> { - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.RFC_1123_DATE_TIME; - - @Override - public LocalDateTime read(JsonReader in) throws IOException { - try { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } else { - return LocalDateTime.parse(in.nextString(), FORMATTER); - } - - } catch (DateTimeParseException e) { - throw new JsonParseException("invalid date", e); - } - } +public class SoLocalDateTimeTypeAdapter extends LocalDateTimeTypeAdapter { - @Override - public void write(JsonWriter out, LocalDateTime value) throws IOException { - if (value == null) { - out.nullValue(); - } else { - String text = value.format(FORMATTER); - out.value(text); - } + public SoLocalDateTimeTypeAdapter() { + super(DateTimeFormatter.RFC_1123_DATE_TIME); } } |