From: Ajith Sreekumar Date: Thu, 3 Dec 2020 10:02:19 +0000 (+0000) Subject: Merge "Remove unused imports" X-Git-Tag: 2.4.0~44 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=d0e612882c86222dbc1560b1282de42cd245a905;hp=ec488290e3aa12cc7fcdf44cc7744bceae89af7f;p=policy%2Fmodels.git Merge "Remove unused imports" --- 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 { - 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); } }