Package com.sap.cloud.sdk.result
Class GsonResultObject
java.lang.Object
com.sap.cloud.sdk.result.GsonResultObject
- All Implemented Interfaces:
ResultElement,ResultObject
ResultObject implementation based on a JsonObject.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.google.gson.JsonObjectThe underlying JSON object.protected final GsonResultElementFactoryTheGsonResultElementFactoryto derive GSON builder from. -
Constructor Summary
ConstructorsConstructorDescriptionGsonResultObject(com.google.gson.JsonObject jsonObject, GsonResultElementFactory resultElementFactory) Creates a newGsonResultObjectinstance. -
Method Summary
Modifier and TypeMethodDescription<T> TReturns a value from this element.<T> TReturns thisResultObjectcasted into the given typeT.In case thisResultElementis considered aResultPrimitive, use this method to access its value asBigDecimal.In case thisResultElementis considered aResultPrimitive, use this method to access its value asBigInteger.booleanIn case thisResultElementis considered aResultPrimitive, use this method to access its value asboolean.byteasByte()In case thisResultElementis considered aResultPrimitive, use this method to access its value asbyte.charIn case thisResultElementis considered aResultPrimitive, use this method to access its value aschar.doubleasDouble()In case thisResultElementis considered aResultPrimitive, use this method to access its value asdouble.floatasFloat()In case thisResultElementis considered aResultPrimitive, use this method to access its value asfloat.intIn case thisResultElementis considered aResultPrimitive, use this method to access its value asint.longasLong()In case thisResultElementis considered aResultPrimitive, use this method to access its value aslong.shortasShort()In case thisResultElementis considered aResultPrimitive, use this method to access its value asshort.asString()In case thisResultElementis considered aResultPrimitive, use this method to access its value asString.protected booleanbooleanReturns the element with the given name from this result.Returns thisResultElementas an instance ofResultCollection.Returns thisResultElementas an instance ofResultObject.Returns thisResultElementas an instance ofResultPrimitive.com.google.gson.JsonObjectThe underlying JSON object.TheGsonResultElementFactoryto derive GSON builder from.inthashCode()booleanChecks whether thisResultElementrepresents a collection of result elements and, therefore, is aResultCollection.booleanChecks whether thisResultElementrepresents a structured object and, therefore, is aResultObject.booleanChecks whether thisResultElementrepresents an unstructured value and, therefore, is aResultPrimitive.toString()
-
Field Details
-
jsonObject
protected final com.google.gson.JsonObject jsonObjectThe underlying JSON object. -
resultElementFactory
TheGsonResultElementFactoryto derive GSON builder from.
-
-
Constructor Details
-
GsonResultObject
public GsonResultObject(com.google.gson.JsonObject jsonObject, GsonResultElementFactory resultElementFactory) Creates a newGsonResultObjectinstance.- Parameters:
jsonObject- The underlying JSON object.resultElementFactory- TheGsonResultElementFactoryto derive GSON builder from.
-
-
Method Details
-
isResultPrimitive
public boolean isResultPrimitive()Description copied from interface:ResultElementChecks whether thisResultElementrepresents an unstructured value and, therefore, is aResultPrimitive.- Specified by:
isResultPrimitivein interfaceResultElement- Returns:
- True of this object is a
ResultPrimitive, otherwise false.
-
isResultCollection
public boolean isResultCollection()Description copied from interface:ResultElementChecks whether thisResultElementrepresents a collection of result elements and, therefore, is aResultCollection.- Specified by:
isResultCollectionin interfaceResultElement- Returns:
- True of this object is a
ResultCollection, otherwise false.
-
isResultObject
public boolean isResultObject()Description copied from interface:ResultElementChecks whether thisResultElementrepresents a structured object and, therefore, is aResultObject.- Specified by:
isResultObjectin interfaceResultElement- Returns:
- True of this object is a
ResultObject, otherwise false.
-
getAsPrimitive
Description copied from interface:ResultElementReturns thisResultElementas an instance ofResultPrimitive.- Specified by:
getAsPrimitivein interfaceResultElement- Returns:
- An instance of
ResultPrimitive. - Throws:
UnsupportedOperationException- If the cast intoResultPrimitivefailed, e.g. in case it is not a primitive.
-
getAsCollection
Description copied from interface:ResultElementReturns thisResultElementas an instance ofResultCollection.- Specified by:
getAsCollectionin interfaceResultElement- Returns:
- An instance of
ResultCollection. - Throws:
UnsupportedOperationException- If the cast intoResultCollectionfailed, e.g. in case it is not a collection.
-
getAsObject
Description copied from interface:ResultElementReturns thisResultElementas an instance ofResultObject.- Specified by:
getAsObjectin interfaceResultElement- Returns:
- An instance of
ResultObject.
-
asBoolean
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asboolean.- Specified by:
asBooleanin interfaceResultElement- Returns:
booleanvalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asboolean.
-
asByte
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asbyte.- Specified by:
asBytein interfaceResultElement- Returns:
bytevalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asbyte.
-
asCharacter
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value aschar.- Specified by:
asCharacterin interfaceResultElement- Returns:
charvalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented aschar.
-
asString
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asString.- Specified by:
asStringin interfaceResultElement- Returns:
Stringobject.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asString.
-
asInteger
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asint.- Specified by:
asIntegerin interfaceResultElement- Returns:
intvalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asint.
-
asShort
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asshort.- Specified by:
asShortin interfaceResultElement- Returns:
shortvalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asshort.
-
asLong
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value aslong.- Specified by:
asLongin interfaceResultElement- Returns:
longvalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented aslong.
-
asFloat
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asfloat.- Specified by:
asFloatin interfaceResultElement- Returns:
floatvalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asfloat.
-
asDouble
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asdouble.- Specified by:
asDoublein interfaceResultElement- Returns:
doublevalue.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asdouble.
-
asBigInteger
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asBigInteger.- Specified by:
asBigIntegerin interfaceResultElement- Returns:
BigIntegerobject.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asBigInteger.
-
asBigDecimal
Description copied from interface:ResultElementIn case thisResultElementis considered aResultPrimitive, use this method to access its value asBigDecimal.- Specified by:
asBigDecimalin interfaceResultElement- Returns:
BigDecimalobject.- Throws:
UnsupportedOperationException- If thisResultElementis not considered aResultPrimitiveor its value cannot be represented asBigDecimal.
-
get
@Nullable public ResultElement get(@Nonnull String elementName) throws UnsupportedOperationException Returns the element with the given name from this result.- Specified by:
getin interfaceResultObject- Parameters:
elementName- The name of the element to be accessed.- Returns:
- An instance of
GsonResultPrimitiverepresenting the corresponding element. - Throws:
UnsupportedOperationException- If the element is not an instance ofResultObject.
-
as
Returns a value from this element. The value is represented as an object of the given type.Important: In order to deserialize a result element to an object of a given type, you have to annotate all relevant field members of the respective class with
ElementName. For example:class MyObject { @ElementName( "MANDT" ) SapClient sapClient; }- Specified by:
asin interfaceResultObject- Type Parameters:
T- The type the result object shall be casted to.- Parameters:
objectType- The type into which the element value should be converted.- Returns:
- The value as object of type
T. - Throws:
UnsupportedOperationException- If the value could not be converted to the given type.
-
as
Description copied from interface:ResultObjectReturns thisResultObjectcasted into the given typeT.- Specified by:
asin interfaceResultObject- Type Parameters:
T- The type the result object shall be casted to.- Parameters:
objectType- TheTypeof the typeT- Returns:
- An instance of
T. - Throws:
UnsupportedOperationException- If the cast into the given object type failed.
-
getJsonObject
public com.google.gson.JsonObject getJsonObject()The underlying JSON object. -
getResultElementFactory
TheGsonResultElementFactoryto derive GSON builder from. -
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-