Class AbstractResponse

java.lang.Object
pro.mypvit.responses.AbstractResponse
Direct Known Subclasses:
BalanceResponse, KycResponse, StatusResponse, TokenResponse, TransactionLinkResponse, TransactionRestResponse

public abstract class AbstractResponse extends Object
Abstract base class for response objects in the MyPVit SDK.

This class provides a shared functionality to deserialize JSON strings into response objects. It ensures consistent deserialization by using a pre-configured Gson instance with a specific field naming policy.

Key Features:
  • Generic deserialization method for converting JSON strings into specific response types.
  • Uses FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES to handle API responses that use snake_case field naming.
  • Designed to be extended by specific response classes in the SDK.
Usage: Subclasses should extend this class to inherit the `fromJson` method for easy deserialization.
  • Constructor Details

    • AbstractResponse

      public AbstractResponse()
      Default constructor
  • Method Details

    • fromJson

      public static <T extends AbstractResponse> T fromJson(String json, Class<T> clazz)
      Converts a JSON string into an instance of a specified subclass of AbstractResponse.

      This method uses a generic type to allow deserialization into any class that extends AbstractResponse.

      Type Parameters:
      T - The type of the subclass.
      Parameters:
      json - The JSON string to deserialize.
      clazz - The class type of the subclass to deserialize into.
      Returns:
      An instance of the specified subclass populated with data from the JSON string.
      Throws:
      com.google.gson.JsonSyntaxException - if the JSON string is not a valid representation for the specified class.