Package com.algorithmia.algo
Class AlgoResponse
- java.lang.Object
-
- com.algorithmia.algo.AlgoResponse
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
AlgoFailure
,AlgoSuccess
public abstract class AlgoResponse extends java.lang.Object implements java.io.Serializable
A generic result, can be either AlgoSuccess or AlgoFailure- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AlgoResponse()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> T
as(TypeToken typeToken)
Convert the result to a specific type.protected abstract <T> T
as(java.lang.Class<T> returnClass)
Convert the result to a specific classprotected abstract <T> T
as(java.lang.reflect.Type returnType)
Convert the result to a specific typeabstract java.lang.String
asJsonString()
Return JSON representation of the result.abstract java.lang.String
asString()
Return String representation of the result.abstract AlgoAsyncResponse
getAsyncResponse()
abstract Metadata
getMetadata()
abstract java.lang.String
getRawOutput()
Return the raw output of the algorithm if it was called with AlgorithmOutputType.RAW This is the only valid way to retrieve a result from a RAW request.abstract boolean
isFailure()
abstract boolean
isSuccess()
-
-
-
Method Detail
-
isSuccess
public abstract boolean isSuccess()
-
isFailure
public abstract boolean isFailure()
-
getMetadata
public abstract Metadata getMetadata() throws AlgorithmException
- Throws:
AlgorithmException
-
getAsyncResponse
public abstract AlgoAsyncResponse getAsyncResponse() throws AlgorithmException
- Throws:
AlgorithmException
-
as
protected abstract <T> T as(java.lang.Class<T> returnClass) throws AlgorithmException
Convert the result to a specific class- Type Parameters:
T
- the type that the response will be deserialized into- Parameters:
returnClass
- the class used by the deserializer (should correspond with T)- Returns:
- the result, if this is AlgoSuccess
- Throws:
AlgorithmException
- the error, if this is AlgoFailure
-
as
protected abstract <T> T as(java.lang.reflect.Type returnType) throws AlgorithmException
Convert the result to a specific type- Type Parameters:
T
- the type that the response will be deserialized into- Parameters:
returnType
- the type used by the deserializer (should correspond with T)- Returns:
- the result, if this is AlgoSuccess
- Throws:
AlgorithmException
- the error, if this is AlgoFailure
-
as
public <T> T as(TypeToken typeToken) throws AlgorithmException
Convert the result to a specific type. To avoid type erasure, be sure to instantiate as an anonymous class:new TypeToken<MyClass>(){}
- Type Parameters:
T
- the type that the response will be deserialized into- Parameters:
typeToken
- the type used by the deserializer (should correspond with T)- Returns:
- the result, if this is AlgoSuccess
- Throws:
AlgorithmException
- the error, if this is AlgoFailure
-
asJsonString
public abstract java.lang.String asJsonString() throws AlgorithmException
Return JSON representation of the result.- Returns:
- the result, if this is AlgoSuccess
- Throws:
AlgorithmException
- the error, if this is AlgoFailure
-
asString
public abstract java.lang.String asString() throws AlgorithmException
Return String representation of the result.- Returns:
- the result, if this is AlgoSuccess
- Throws:
AlgorithmException
- the error, if this is AlgoFailure
-
getRawOutput
public abstract java.lang.String getRawOutput() throws AlgorithmException
Return the raw output of the algorithm if it was called with AlgorithmOutputType.RAW This is the only valid way to retrieve a result from a RAW request. Will return null for any other AlgorithmOutputType- Returns:
- the result, if this is AlgoSuccess
- Throws:
AlgorithmException
- the error, if this is AlgoFailure
-
-