Class GGResponse<T extends GGResponseObject>

    • Constructor Summary

      Constructors 
      Constructor Description
      GGResponse​(com.google.gson.JsonObject responseRoot, java.lang.Class<T> toClass)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.gson.JsonArray getActionRecords()
      The unprocessed actionRecords field of the response.
      T getData()
      The deserialized data.
      java.util.List<GGError> getErrors()
      The errors field.
      DeserializationException getException()
      The Exception that occurred during deserialization.
      com.google.gson.JsonObject getExtensions()
      The unprocessed extensions field of the response.
      com.google.gson.JsonObject getResponseRoot()
      The unprocessed JsonObject of the response.
      <U> U map​(java.util.function.Function<GGResponse<T>,​U> onError, java.util.function.Function<T,​U> onSuccess)
      Applies either itself to onError, if either the errors field is present or deserialization failed, or the deserialized data to onSuccess if that is not the case, and returns the result.
      GGResponse<T> onError​(java.util.function.Consumer<GGResponse<T>> consumer)
      The consumer is executed only if the errors field is present or deserialization failed.
      GGResponse<T> onSuccess​(java.util.function.Consumer<T> consumer)
      The consumer is executed only if the errors field is not present and deserialization was successful.
      • Methods inherited from class java.lang.Object

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

      • GGResponse

        public GGResponse​(@Nonnull
                          com.google.gson.JsonObject responseRoot,
                          @Nonnull
                          java.lang.Class<T> toClass)
        Throws:
        java.lang.IllegalArgumentException - if responseRoot or toClass are null
    • Method Detail

      • map

        public <U> U map​(@Nonnull
                         java.util.function.Function<GGResponse<T>,​U> onError,
                         @Nonnull
                         java.util.function.Function<T,​U> onSuccess)
        Applies either itself to onError, if either the errors field is present or deserialization failed, or the deserialized data to onSuccess if that is not the case, and returns the result.
        Type Parameters:
        U - the return type
        Parameters:
        onError - the function to apply if the errors field is present or deserialization failed
        onSuccess - the function to apply if the errors field is not present and deserialization succeeded
        Returns:
        the result of the applied function
        Throws:
        java.lang.IllegalStateException - if onError or onSuccess are null
      • onError

        public GGResponse<T> onError​(@Nonnull
                                     java.util.function.Consumer<GGResponse<T>> consumer)
        The consumer is executed only if the errors field is present or deserialization failed.
        Parameters:
        consumer - the consumer to execute
        Returns:
        itself for chaining
        Throws:
        java.lang.IllegalStateException - if consumer is null
      • onSuccess

        public GGResponse<T> onSuccess​(@Nonnull
                                       java.util.function.Consumer<T> consumer)
        The consumer is executed only if the errors field is not present and deserialization was successful.
        Parameters:
        consumer - the consumer to execute
        Returns:
        itself for chaining
        Throws:
        java.lang.IllegalStateException - if consumer is null
      • getResponseRoot

        @Nonnull
        public com.google.gson.JsonObject getResponseRoot()
        The unprocessed JsonObject of the response.
        Returns:
        the response root
      • getData

        @Nullable
        public T getData()
        The deserialized data.
        Returns:
        the deserialized data or null if deserialization failed
      • getException

        @Nullable
        public DeserializationException getException()
        The Exception that occurred during deserialization.
        Returns:
        The DeserializationException or null if it deserialization was successful
      • getErrors

        @Nullable
        public java.util.List<GGError> getErrors()
        The errors field.
        Returns:
        The errors field as a List<GGError>
      • getExtensions

        @Nullable
        public com.google.gson.JsonObject getExtensions()
        The unprocessed extensions field of the response.
        Returns:
        the extensions field
      • getActionRecords

        @Nullable
        public com.google.gson.JsonArray getActionRecords()
        The unprocessed actionRecords field of the response.
        Returns:
        the actionRecords field