public class GsonResultObject extends Object implements ResultObject
ResultObject implementation based on a JsonObject.| Modifier and Type | Field and Description |
|---|---|
protected com.google.gson.JsonObject |
jsonObject
The underlying JSON object.
|
protected GsonResultElementFactory |
resultElementFactory
The
GsonResultElementFactory to derive GSON builder from. |
| Constructor and Description |
|---|
GsonResultObject(com.google.gson.JsonObject jsonObject,
GsonResultElementFactory resultElementFactory) |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
as(Class<T> objectType)
Returns a value from this element.
|
<T> T |
as(Type objectType)
Returns this
ResultObject casted into the given type T. |
BigDecimal |
asBigDecimal()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as BigDecimal. |
BigInteger |
asBigInteger()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as BigInteger. |
boolean |
asBoolean()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as boolean. |
byte |
asByte()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as byte. |
char |
asCharacter()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as char. |
double |
asDouble()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as double. |
float |
asFloat()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as float. |
int |
asInteger()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as int. |
long |
asLong()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as long. |
short |
asShort()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as short. |
String |
asString()
In case this
ResultElement is considered a ResultPrimitive, use this method to access its value
as String. |
protected boolean |
canEqual(Object other) |
boolean |
equals(Object o) |
ResultElement |
get(String elementName)
Returns the element with the given name from this result.
|
ResultCollection |
getAsCollection()
Returns this
ResultElement as an instance of ResultCollection. |
ResultObject |
getAsObject()
Returns this
ResultElement as an instance of ResultObject. |
ResultPrimitive |
getAsPrimitive()
Returns this
ResultElement as an instance of ResultPrimitive. |
com.google.gson.JsonObject |
getJsonObject()
The underlying JSON object.
|
GsonResultElementFactory |
getResultElementFactory()
The
GsonResultElementFactory to derive GSON builder from. |
int |
hashCode() |
boolean |
isResultCollection()
Checks whether this
ResultElement represents a collection of result elements and, therefore, is a
ResultCollection. |
boolean |
isResultObject()
Checks whether this
ResultElement represents a structured object and, therefore, is a
ResultObject. |
boolean |
isResultPrimitive()
Checks whether this
ResultElement represents an unstructured value and, therefore, is a
ResultPrimitive. |
String |
toString() |
protected final com.google.gson.JsonObject jsonObject
protected final GsonResultElementFactory resultElementFactory
GsonResultElementFactory to derive GSON builder from.public GsonResultObject(com.google.gson.JsonObject jsonObject,
GsonResultElementFactory resultElementFactory)
public boolean isResultPrimitive()
ResultElement represents an unstructured value and, therefore, is a
ResultPrimitive.isResultPrimitive in interface ResultElementResultPrimitive, otherwise false.public boolean isResultCollection()
ResultElement represents a collection of result elements and, therefore, is a
ResultCollection.isResultCollection in interface ResultElementResultCollection, otherwise false.public boolean isResultObject()
ResultElement represents a structured object and, therefore, is a
ResultObject.isResultObject in interface ResultElementResultObject, otherwise false.@Nonnull public ResultPrimitive getAsPrimitive() throws UnsupportedOperationException
ResultElement as an instance of ResultPrimitive.getAsPrimitive in interface ResultElementResultPrimitive.UnsupportedOperationException - If the cast into ResultPrimitive failed, e.g. in case it is not a primitive.@Nonnull public ResultCollection getAsCollection() throws UnsupportedOperationException
ResultElement as an instance of ResultCollection.getAsCollection in interface ResultElementResultCollection.UnsupportedOperationException - If the cast into ResultCollection failed, e.g. in case it is not a collection.@Nonnull public ResultObject getAsObject()
ResultElement as an instance of ResultObject.getAsObject in interface ResultElementResultObject.public boolean asBoolean()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as boolean.asBoolean in interface ResultElementboolean value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as boolean.public byte asByte()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as byte.asByte in interface ResultElementbyte value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as byte.public char asCharacter()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as char.asCharacter in interface ResultElementchar value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as char.@Nonnull public String asString() throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as String.asString in interface ResultElementString object.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as String.public int asInteger()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as int.asInteger in interface ResultElementint value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as int.public short asShort()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as short.asShort in interface ResultElementshort value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as short.public long asLong()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as long.asLong in interface ResultElementlong value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as long.public float asFloat()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as float.asFloat in interface ResultElementfloat value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as float.public double asDouble()
throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as double.asDouble in interface ResultElementdouble value.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as double.@Nonnull public BigInteger asBigInteger() throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as BigInteger.asBigInteger in interface ResultElementBigInteger object.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as BigInteger.@Nonnull public BigDecimal asBigDecimal() throws UnsupportedOperationException
ResultElement is considered a ResultPrimitive, use this method to access its value
as BigDecimal.asBigDecimal in interface ResultElementBigDecimal object.UnsupportedOperationException - If this ResultElement is not considered a ResultPrimitive or its value cannot be
represented as BigDecimal.@Nullable public ResultElement get(@Nonnull String elementName) throws UnsupportedOperationException
get in interface ResultObjectelementName - The name of the element to be accessed.GsonResultPrimitive representing the corresponding element.UnsupportedOperationException - If the element is not an instance of ResultObject.@Nonnull public <T> T as(@Nonnull Class<T> objectType) throws UnsupportedOperationException
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;
}
as in interface ResultObjectT - The type the result object shall be casted to.objectType - The type into which the element value should be converted.T.UnsupportedOperationException - If the value could not be converted to the given type.@Nonnull public <T> T as(@Nonnull Type objectType) throws UnsupportedOperationException
ResultObjectResultObject casted into the given type T.as in interface ResultObjectT - The type the result object shall be casted to.objectType - The Type of the type TT.UnsupportedOperationException - If the cast into the given object type failed.public com.google.gson.JsonObject getJsonObject()
public GsonResultElementFactory getResultElementFactory()
GsonResultElementFactory to derive GSON builder from.Copyright © 2021 SAP SE. All rights reserved.