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
Modifier and TypeFieldDescriptionprotected final com.google.gson.JsonObject
The underlying JSON object.protected final GsonResultElementFactory
TheGsonResultElementFactory
to derive GSON builder from. -
Constructor Summary
ConstructorDescriptionGsonResultObject
(com.google.gson.JsonObject jsonObject, GsonResultElementFactory resultElementFactory) Creates a newGsonResultObject
instance. -
Method Summary
Modifier and TypeMethodDescription<T> T
Returns a value from this element.<T> T
Returns thisResultObject
casted into the given typeT
.In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asBigDecimal
.In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asBigInteger
.boolean
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asboolean
.byte
asByte()
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asbyte
.char
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value aschar
.double
asDouble()
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asdouble
.float
asFloat()
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asfloat
.int
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asint
.long
asLong()
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value aslong
.short
asShort()
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asshort
.asString()
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asString
.protected boolean
boolean
Returns the element with the given name from this result.Returns thisResultElement
as an instance ofResultCollection
.Returns thisResultElement
as an instance ofResultObject
.Returns thisResultElement
as an instance ofResultPrimitive
.com.google.gson.JsonObject
The underlying JSON object.TheGsonResultElementFactory
to derive GSON builder from.int
hashCode()
boolean
Checks whether thisResultElement
represents a collection of result elements and, therefore, is aResultCollection
.boolean
Checks whether thisResultElement
represents a structured object and, therefore, is aResultObject
.boolean
Checks whether thisResultElement
represents an unstructured value and, therefore, is aResultPrimitive
.toString()
-
Field Details
-
jsonObject
protected final com.google.gson.JsonObject jsonObjectThe underlying JSON object. -
resultElementFactory
TheGsonResultElementFactory
to derive GSON builder from.
-
-
Constructor Details
-
GsonResultObject
public GsonResultObject(com.google.gson.JsonObject jsonObject, GsonResultElementFactory resultElementFactory) Creates a newGsonResultObject
instance.- Parameters:
jsonObject
- The underlying JSON object.resultElementFactory
- TheGsonResultElementFactory
to derive GSON builder from.
-
-
Method Details
-
isResultPrimitive
public boolean isResultPrimitive()Description copied from interface:ResultElement
Checks whether thisResultElement
represents an unstructured value and, therefore, is aResultPrimitive
.- Specified by:
isResultPrimitive
in interfaceResultElement
- Returns:
- True of this object is a
ResultPrimitive
, otherwise false.
-
isResultCollection
public boolean isResultCollection()Description copied from interface:ResultElement
Checks whether thisResultElement
represents a collection of result elements and, therefore, is aResultCollection
.- Specified by:
isResultCollection
in interfaceResultElement
- Returns:
- True of this object is a
ResultCollection
, otherwise false.
-
isResultObject
public boolean isResultObject()Description copied from interface:ResultElement
Checks whether thisResultElement
represents a structured object and, therefore, is aResultObject
.- Specified by:
isResultObject
in interfaceResultElement
- Returns:
- True of this object is a
ResultObject
, otherwise false.
-
getAsPrimitive
Description copied from interface:ResultElement
Returns thisResultElement
as an instance ofResultPrimitive
.- Specified by:
getAsPrimitive
in interfaceResultElement
- Returns:
- An instance of
ResultPrimitive
. - Throws:
UnsupportedOperationException
- If the cast intoResultPrimitive
failed, e.g. in case it is not a primitive.
-
getAsCollection
Description copied from interface:ResultElement
Returns thisResultElement
as an instance ofResultCollection
.- Specified by:
getAsCollection
in interfaceResultElement
- Returns:
- An instance of
ResultCollection
. - Throws:
UnsupportedOperationException
- If the cast intoResultCollection
failed, e.g. in case it is not a collection.
-
getAsObject
Description copied from interface:ResultElement
Returns thisResultElement
as an instance ofResultObject
.- Specified by:
getAsObject
in interfaceResultElement
- Returns:
- An instance of
ResultObject
.
-
asBoolean
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asboolean
.- Specified by:
asBoolean
in interfaceResultElement
- Returns:
boolean
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asboolean
.
-
asByte
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asbyte
.- Specified by:
asByte
in interfaceResultElement
- Returns:
byte
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asbyte
.
-
asCharacter
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value aschar
.- Specified by:
asCharacter
in interfaceResultElement
- Returns:
char
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented aschar
.
-
asString
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asString
.- Specified by:
asString
in interfaceResultElement
- Returns:
String
object.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asString
.
-
asInteger
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asint
.- Specified by:
asInteger
in interfaceResultElement
- Returns:
int
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asint
.
-
asShort
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asshort
.- Specified by:
asShort
in interfaceResultElement
- Returns:
short
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asshort
.
-
asLong
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value aslong
.- Specified by:
asLong
in interfaceResultElement
- Returns:
long
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented aslong
.
-
asFloat
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asfloat
.- Specified by:
asFloat
in interfaceResultElement
- Returns:
float
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asfloat
.
-
asDouble
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asdouble
.- Specified by:
asDouble
in interfaceResultElement
- Returns:
double
value.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asdouble
.
-
asBigInteger
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asBigInteger
.- Specified by:
asBigInteger
in interfaceResultElement
- Returns:
BigInteger
object.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or its value cannot be represented asBigInteger
.
-
asBigDecimal
Description copied from interface:ResultElement
In case thisResultElement
is considered aResultPrimitive
, use this method to access its value asBigDecimal
.- Specified by:
asBigDecimal
in interfaceResultElement
- Returns:
BigDecimal
object.- Throws:
UnsupportedOperationException
- If thisResultElement
is not considered aResultPrimitive
or 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:
get
in interfaceResultObject
- Parameters:
elementName
- The name of the element to be accessed.- Returns:
- An instance of
GsonResultPrimitive
representing 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:
as
in 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:ResultObject
Returns thisResultObject
casted into the given typeT
.- Specified by:
as
in interfaceResultObject
- Type Parameters:
T
- The type the result object shall be casted to.- Parameters:
objectType
- TheType
of 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
TheGsonResultElementFactory
to derive GSON builder from. -
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-