Klasse ResponseValidator

java.lang.Object
net.dzultra.jsa.ResponseValidator

public class ResponseValidator extends Object
Utility class for validating JSON responses from the Scryfall API.

This class provides helper methods to verify whether a given JSON response matches expected structural and type constraints by deserializing it into predefined record types.

  • Konstruktordetails

    • ResponseValidator

      public ResponseValidator()
  • Methodendetails

    • isValidResponseSingle

      public static boolean isValidResponseSingle(com.google.gson.Gson gson, String response, String type)
      Validates whether the given JSON response contains a top-level object with the specified type.

      The response is deserialized into a TypeRecord, and the type field is compared against the expected value.

      Parameter:
      gson - the Gson instance used for deserialization
      response - the raw JSON response as a string
      type - the expected value of the type field
      Gibt zurück:
      true if the response is valid and matches the expected type; false if parsing fails or the type does not match
    • isValidResponseDouble

      public static boolean isValidResponseDouble(com.google.gson.Gson gson, String response, String type1, String type2)
      Validates whether the given JSON response contains a top-level object with a specific type, and a nested data array whose first element has a specific secondary type.

      The response is deserialized into a DataTypeRecord, and both the top-level type and the type of the first element in the data array are validated.

      Parameter:
      gson - the Gson instance used for deserialization
      response - the raw JSON response as a string
      type1 - the expected top-level type
      type2 - the expected type of the first element in data
      Gibt zurück:
      true if both type checks pass; false if parsing fails or any type does not match
    • isValidSymbologyResponse

      public static boolean isValidSymbologyResponse(com.google.gson.Gson gson, String response)
      Validates whether the given JSON response represents a valid symbology response.

      A response is considered valid if:

      • The top-level type is "mana_cost", or
      • The top-level type is "list" and the first element in the data array has type "card_symbol".
      Parameter:
      gson - the Gson instance used for deserialization
      response - the raw JSON response as a string
      Gibt zurück:
      true if the response matches the expected symbology formats; false if parsing fails or the structure is invalid