public class RequestBuilder<T> extends AbstractBuilder
ObjectMapper and actual request performing to Transport.ERROR, ID, JSONRPC, mapper, METHOD, PARAMS, RESULT, transport, VERSION_2_0| Constructor and Description |
|---|
RequestBuilder(Transport transport,
com.fasterxml.jackson.databind.ObjectMapper mapper)
Creates a new default request builder without actual parameters
|
| Modifier and Type | Method and Description |
|---|---|
T |
execute()
Execute a request through
Transport and convert a not null response to an expected type |
T |
executeNullable()
Execute a request through
Transport and convert a nullable response to an expected type |
RequestBuilder<T> |
id(Integer id)
Sets a request id as an integer value
|
RequestBuilder<T> |
id(Long id)
Sets a request id as a long value
|
RequestBuilder<T> |
id(String id)
Sets a request id as a string value
|
RequestBuilder<T> |
method(String method)
Sets a request method
|
RequestBuilder<T> |
param(String name,
Object value)
Adds a new parameter to current request parameters.
|
RequestBuilder<T> |
params(Object... values)
Sets request parameters to request parameters.
|
<NT> RequestBuilder<NT> |
returnAs(Class<NT> responseType)
Sets expected return type.
|
<NT> RequestBuilder<NT> |
returnAs(com.fasterxml.jackson.core.type.TypeReference<NT> tr)
Sets expected return type as a generic type, e.g.
|
<E> RequestBuilder<E[]> |
returnAsArray(Class<E> elementType)
Sets expected return type as an array
|
<E> RequestBuilder<Collection<E>> |
returnAsCollection(Class<? extends Collection<?>> collectionType,
Class<E> elementType)
Sets expected return type as a collection of objects.
|
<E> RequestBuilder<List<E>> |
returnAsList(Class<E> elementType)
Sets expected return type as a list of objects
|
<V> RequestBuilder<Map<String,V>> |
returnAsMap(Class<? extends Map<?,?>> mapClass,
Class<V> valueType)
Sets expected return type as a map of objects.
|
<E> RequestBuilder<Set<E>> |
returnAsSet(Class<E> elementType)
Sets expected return type as a set of objects
|
arrayParams, objectParams, requestpublic RequestBuilder(Transport transport, com.fasterxml.jackson.databind.ObjectMapper mapper)
transport - transport for request performingmapper - mapper for JSON processingpublic RequestBuilder<T> id(Long id)
id - a request idpublic RequestBuilder<T> id(Integer id)
id - a request idpublic RequestBuilder<T> id(String id)
id - a request idpublic RequestBuilder<T> method(String method)
method - a request methodpublic RequestBuilder<T> param(String name, Object value)
name - parameter namevalue - parameter valuepublic RequestBuilder<T> params(Object... values)
values - array of parameterspublic <NT> RequestBuilder<NT> returnAs(Class<NT> responseType)
NT - new return typeresponseType - expected return typepublic <E> RequestBuilder<List<E>> returnAsList(Class<E> elementType)
E - generic list typeelementType - type of elements of a listpublic <E> RequestBuilder<Set<E>> returnAsSet(Class<E> elementType)
E - generic set typeelementType - type of elements of a setpublic <E> RequestBuilder<Collection<E>> returnAsCollection(Class<? extends Collection<?>> collectionType, Class<E> elementType)
QueueE - type of elements of a collectioncollectionType - generic collection typeelementType - type of elements of a collectionpublic <E> RequestBuilder<E[]> returnAsArray(Class<E> elementType)
E - generic array typeelementType - type of elements of an arraypublic <V> RequestBuilder<Map<String,V>> returnAsMap(Class<? extends Map<?,?>> mapClass, Class<V> valueType)
V - generic map value typemapClass - expected map interface or implementation,
e.g. Map, HashMap.
LinkedHashMap, SortedMapvalueType - map value typepublic <NT> RequestBuilder<NT> returnAs(com.fasterxml.jackson.core.type.TypeReference<NT> tr)
NT - a generic typetr - type referencepublic T execute()
Transport and convert a not null response to an expected typeJsonRpcException - in case of JSON-RPC error, returned by the serverIllegalStateException - if the response is nullpublic T executeNullable()
Transport and convert a nullable response to an expected typeJsonRpcException - in case of JSON-RPC error, returned by the serverCopyright © 2018. All rights reserved.