Package net.dzultra.jsa
Klasse ResponseValidator
java.lang.Object
net.dzultra.jsa.ResponseValidator
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.
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic booleanisValidResponseDouble(com.google.gson.Gson gson, String response, String type1, String type2) Validates whether the given JSON response contains a top-level object with a specifictype, and a nesteddataarray whose first element has a specific secondary type.static booleanisValidResponseSingle(com.google.gson.Gson gson, String response, String type) Validates whether the given JSON response contains a top-level object with the specifiedtype.static booleanisValidSymbologyResponse(com.google.gson.Gson gson, String response) Validates whether the given JSON response represents a valid symbology response.
-
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 specifiedtype.The response is deserialized into a
TypeRecord, and thetypefield is compared against the expected value.- Parameter:
gson- theGsoninstance used for deserializationresponse- the raw JSON response as a stringtype- the expected value of thetypefield- Gibt zurück:
trueif the response is valid and matches the expected type;falseif 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 specifictype, and a nesteddataarray whose first element has a specific secondary type.The response is deserialized into a
DataTypeRecord, and both the top-leveltypeand thetypeof the first element in thedataarray are validated.- Parameter:
gson- theGsoninstance used for deserializationresponse- the raw JSON response as a stringtype1- the expected top-leveltypetype2- the expectedtypeof the first element indata- Gibt zurück:
trueif both type checks pass;falseif parsing fails or any type does not match
-
isValidSymbologyResponse
Validates whether the given JSON response represents a valid symbology response.A response is considered valid if:
- The top-level
typeis"mana_cost", or - The top-level
typeis"list"and the first element in thedataarray has type"card_symbol".
- Parameter:
gson- theGsoninstance used for deserializationresponse- the raw JSON response as a string- Gibt zurück:
trueif the response matches the expected symbology formats;falseif parsing fails or the structure is invalid
- The top-level
-