Package server

Class Gson_InstantTypeAdapter

java.lang.Object
com.google.gson.TypeAdapter<Instant>
server.Gson_InstantTypeAdapter

public class Gson_InstantTypeAdapter extends com.google.gson.TypeAdapter<Instant>
Source - https://stackoverflow.com/a/75502641
Posted by Basil Bourque, modified by community. See post 'Timeline' for change history
Retrieved 2026-02-03, License - CC BY-SA 4.0
Doc comments provided by Henning.
TypeAdapter for the Instant data type since it cant be natively serialized into json by Gson.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor added to prevent javadoc warning
  • Method Summary

    Modifier and Type
    Method
    Description
    read(com.google.gson.stream.JsonReader jsonReader)
    Deserialization step.
    void
    write(com.google.gson.stream.JsonWriter jsonWriter, Instant instant)
    Serialization step.

    Methods inherited from class com.google.gson.TypeAdapter

    fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Gson_InstantTypeAdapter

      public Gson_InstantTypeAdapter()
      Constructor added to prevent javadoc warning
  • Method Details

    • write

      public void write(com.google.gson.stream.JsonWriter jsonWriter, Instant instant) throws IOException
      Serialization step. Turns the Instant into a String with ISO 8601 format
      Specified by:
      write in class com.google.gson.TypeAdapter<Instant>
      Throws:
      IOException
    • read

      public Instant read(com.google.gson.stream.JsonReader jsonReader) throws IOException
      Deserialization step. Parses the String back into an Instant object.
      Specified by:
      read in class com.google.gson.TypeAdapter<Instant>
      Throws:
      IOException