Package com.shopify.graphql.support
Class AbstractResponse<T extends AbstractResponse>
- java.lang.Object
-
- com.shopify.graphql.support.AbstractResponse<T>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
__Directive,__EnumValue,__Field,__InputValue,__Schema,__Type,_EnumValue,_FieldGroup,_FieldShape,_GraphReport,_Path,_RDFNode,_Resource,_TestResult,_TypeShape,_ValidationReport,_ValidationResult,_ValidationResultSuggestion,ConstraintReificationShape,Graph,GraphType,Literal,MasterGraph,RootRDFQuery,User,WorkflowGraph
public abstract class AbstractResponse<T extends AbstractResponse> extends Object implements Serializable
Created by dylansmith on 2015-11-23.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description HashMap<String,Object>optimisticDataHashMap<String,Object>responseData
-
Constructor Summary
Constructors Constructor Description AbstractResponse()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description List<Node>collectNodes()Objectget(String field)Gets a field as a raw object.com.google.gson.JsonArraygetAsArray(String field)Tries to deserialise and return the given JSON field as an Array.BooleangetAsBoolean(String field)Tries to deserialise and return the given JSON field as a Boolean.DoublegetAsDouble(String field)Tries to deserialise and return the given JSON field as a Double.IntegergetAsInteger(String field)Tries to deserialise and return the given JSON field as an Integer.StringgetAsString(String field)Tries to deserialise and return the given JSON field as a String.protected StringgetFieldName(String key)protected StringgetKey(String field)protected com.google.gson.JsonArrayjsonAsArray(com.google.gson.JsonElement element, String field)protected BooleanjsonAsBoolean(com.google.gson.JsonElement element, String field)protected DoublejsonAsDouble(com.google.gson.JsonElement element, String field)protected IntegerjsonAsInteger(com.google.gson.JsonElement element, String field)protected com.google.gson.JsonObjectjsonAsObject(com.google.gson.JsonElement element, String field)protected StringjsonAsString(com.google.gson.JsonElement element, String field)protected voidreadCustomField(String fieldName, com.google.gson.JsonElement element)Tries to read a custom field from the GraphQL JSON response.abstract booleanunwrapsToObject(String key)TwithAlias(String aliasSuffix)
-
-
-
Method Detail
-
get
public Object get(String field)
Gets a field as a raw object.- Parameters:
field- The name of the field.- Returns:
- The raw object.
-
getAsString
public String getAsString(String field) throws SchemaViolationError
Tries to deserialise and return the given JSON field as a String. The field itself is expected to be stored in the object data as aJsonElement, which is the case for custom simple fields.- Parameters:
field- The name of the field.- Returns:
- The value of the field.
- Throws:
SchemaViolationError- If the field cannot be converted to a String.
-
getAsInteger
public Integer getAsInteger(String field) throws SchemaViolationError
Tries to deserialise and return the given JSON field as an Integer. The field itself is expected to be stored in the object data as aJsonElement, which is the case for custom simple fields.- Parameters:
field- The name of the field.- Returns:
- The value of the field.
- Throws:
SchemaViolationError- If the field cannot be converted to an Integer.
-
getAsDouble
public Double getAsDouble(String field) throws SchemaViolationError
Tries to deserialise and return the given JSON field as a Double. The field itself is expected to be stored in the object data as aJsonElement, which is the case for custom simple fields.- Parameters:
field- The name of the field.- Returns:
- The value of the field.
- Throws:
SchemaViolationError- If the field cannot be converted to a Double.
-
getAsBoolean
public Boolean getAsBoolean(String field) throws SchemaViolationError
Tries to deserialise and return the given JSON field as a Boolean. The field itself is expected to be stored in the object data as aJsonElement, which is the case for custom simple fields.- Parameters:
field- The name of the field.- Returns:
- The value of the field.
- Throws:
SchemaViolationError- If the field cannot be converted to a Boolean.
-
getAsArray
public com.google.gson.JsonArray getAsArray(String field) throws SchemaViolationError
Tries to deserialise and return the given JSON field as an Array. The field itself is expected to be stored in the object data as aJsonElement, which is the case for custom simple fields.- Parameters:
field- The name of the field.- Returns:
- The value of the field.
- Throws:
SchemaViolationError- If the field cannot be converted to an Array.
-
readCustomField
protected void readCustomField(String fieldName, com.google.gson.JsonElement element) throws SchemaViolationError
Tries to read a custom field from the GraphQL JSON response. The method throws a schema violation exception if the field name does not contain the_custom_alias suffix added by the library, which would indicate that the field does not belong to the GraphQL Schema and was not explicitly requested as a custom field.- Parameters:
fieldName- The field name.element- The JSON element parsed by the JSON deserialiser.- Throws:
SchemaViolationError- If the field name does not contain the_custom_suffix.
-
jsonAsString
protected String jsonAsString(com.google.gson.JsonElement element, String field) throws SchemaViolationError
- Throws:
SchemaViolationError
-
jsonAsInteger
protected Integer jsonAsInteger(com.google.gson.JsonElement element, String field) throws SchemaViolationError
- Throws:
SchemaViolationError
-
jsonAsDouble
protected Double jsonAsDouble(com.google.gson.JsonElement element, String field) throws SchemaViolationError
- Throws:
SchemaViolationError
-
jsonAsBoolean
protected Boolean jsonAsBoolean(com.google.gson.JsonElement element, String field) throws SchemaViolationError
- Throws:
SchemaViolationError
-
jsonAsObject
protected com.google.gson.JsonObject jsonAsObject(com.google.gson.JsonElement element, String field) throws SchemaViolationError- Throws:
SchemaViolationError
-
jsonAsArray
protected com.google.gson.JsonArray jsonAsArray(com.google.gson.JsonElement element, String field) throws SchemaViolationError- Throws:
SchemaViolationError
-
unwrapsToObject
public abstract boolean unwrapsToObject(String key)
-
-