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.SerializableA 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> Tas(TypeToken typeToken)Convert the result to a specific type.protected abstract <T> Tas(java.lang.Class<T> returnClass)Convert the result to a specific classprotected abstract <T> Tas(java.lang.reflect.Type returnType)Convert the result to a specific typeabstract java.lang.StringasJsonString()Return JSON representation of the result.abstract java.lang.StringasString()Return String representation of the result.abstract AlgoAsyncResponsegetAsyncResponse()abstract MetadatagetMetadata()abstract java.lang.StringgetRawOutput()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 booleanisFailure()abstract booleanisSuccess()
-
-
-
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 AlgorithmExceptionConvert 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 AlgorithmExceptionConvert 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 AlgorithmExceptionReturn 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 AlgorithmExceptionReturn 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 AlgorithmExceptionReturn 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
-
-