Record Class GsonDocumentSend

java.lang.Object
java.lang.Record
eu.cloudnetservice.driver.document.gson.send.GsonDocumentSend
Record Components:
rootElement - the root object element of the document send.
All Implemented Interfaces:
DocumentSend

public record GsonDocumentSend(@NonNull ObjectElement rootElement) extends Record implements DocumentSend
An implementation of a document send specifically made for gson.
Since:
4.0
  • Field Details

  • Constructor Details

    • GsonDocumentSend

      public GsonDocumentSend(@NonNull @NonNull ObjectElement rootElement)
      Creates an instance of a GsonDocumentSend record class.
      Parameters:
      rootElement - the value for the rootElement record component
  • Method Details

    • fromJsonObject

      @NonNull public static @NonNull DocumentSend fromJsonObject(@NonNull @NonNull com.google.gson.JsonObject object)
      Constructs a document send instance from the given gson json object.
      Parameters:
      object - the json object to construct the document send from.
      Returns:
      the document send constructed from the given json object.
      Throws:
      NullPointerException - if the given json object is null.
    • serializeObject

      @NonNull private static @NonNull ObjectElement serializeObject(@NonNull @NonNull String key, @NonNull @NonNull com.google.gson.JsonObject object)
      Serialises the given gson json object into an object element.
      Parameters:
      key - the key of the given json object.
      object - the object to serialize.
      Returns:
      an object element serialized from the given gson json object.
      Throws:
      NullPointerException - if the given key or json object is null.
    • serializeArray

      @NonNull private static @NonNull ArrayElement serializeArray(@NonNull @NonNull String key, @NonNull @NonNull com.google.gson.JsonArray array)
      Serialises the given gson json array into an array element.
      Parameters:
      key - the key of the given json array.
      array - the array to serialize.
      Returns:
      an array element serialized from the given gson json array.
      Throws:
      NullPointerException - if the given key or json array is null.
    • into

      Receives this document into the given document factory. In normal cases the given document factory should create a new, empty document and import all supported key-value pairs that are supplied by this send into it.

      The receiving process of a document send should never throw an exception unless the given document send contains malformed or invalid data making it impossible to get imported.

      Specified by:
      into in interface DocumentSend
      Parameters:
      factory - the document factory that is supposed to receive this document send.
      Returns:
      a new, empty document containing all supported key-value pairs of the given document send.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • rootElement

      @NonNull public @NonNull ObjectElement rootElement()
      Returns the value of the rootElement record component.
      Specified by:
      rootElement in interface DocumentSend
      Returns:
      the value of the rootElement record component