Class AbstractCalendarAdapter<T>

java.lang.Object
com.google.gson.TypeAdapter<T>
com.sap.cloud.sdk.s4hana.datamodel.odata.adapter.AbstractCalendarAdapter<T>
Type Parameters:
T - The type this adapter should parse.
Direct Known Subclasses:
LocalDateTimeAdapter, LocalTimeAdapter, ZonedDateTimeAdapter

public abstract class AbstractCalendarAdapter<T> extends com.google.gson.TypeAdapter<T>
Abstract base class to be used to easily parse fields which can be read as a Calendar object as a Gson TypeAdapter.

This may be used to specify an adapter for the new Java date API (e.g. LocalDateTime) based on a common conversion logic. This way the logic is split the following way:

General Conversion logic AbstractTypeConverter subclasses (*CalendarConverter)
Gson Adapter AbstractCalendarAdapter subclasses
Jackson (De)Serializer AbstractJacksonCalendar(De)Serializer and subclasses
  • Constructor Details

    • AbstractCalendarAdapter

      public AbstractCalendarAdapter()
  • Method Details

    • convertStringToType

      @Nonnull protected abstract ConvertedObject<T> convertStringToType(@Nonnull String jsonString)
      Converts a string value read from a json property as an instance of the type to be created by this adapter.
      Parameters:
      jsonString - The string value of a json property.
      Returns:
      A ConvertedObject instance containing the resulting object, or is empty if conversion was not possible.
    • convertTypeToString

      @Nonnull protected abstract ConvertedObject<String> convertTypeToString(@Nullable T entity)
      Converts an instance of the type handled by this adapter into a string that can be written as a json value.
      Parameters:
      entity - The entity to convert into a String
      Returns:
      A ConvertedObject instance containing the resulting string, or is empty if conversion was not possible.
    • write

      public void write(@Nonnull com.google.gson.stream.JsonWriter out, @Nullable T value) throws IOException
      Specified by:
      write in class com.google.gson.TypeAdapter<T>
      Throws:
      IOException
    • read

      @Nullable public T read(@Nonnull com.google.gson.stream.JsonReader jsonReader) throws IOException
      Specified by:
      read in class com.google.gson.TypeAdapter<T>
      Throws:
      IOException