Class JsonResultWrapper
java.lang.Object
de.iip_ecosphere.platform.support.json.JsonResultWrapper
- All Implemented Interfaces:
Serializable,Function<Object[],Object>
Uniform JSON way to represent results of operations that may fail.
- Author:
- Holger Eichelberger, SSE
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA function that may throw an exception.static interfaceAllows to track operations.static classRepresents the result w/o exception. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a wrapper object.JsonResultWrapper(JsonResultWrapper.ExceptionFunction func, JsonResultWrapper.OperationCompletedListener listener) Creates a wrapper object.JsonResultWrapper(JsonResultWrapper.ExceptionFunction func, JsonResultWrapper.OperationCompletedListener listener, Function<Object[], String> taskIdSupplier) Creates a wrapper object.JsonResultWrapper(JsonResultWrapper.ExceptionFunction func, Function<Object[], String> taskIdSupplier) Creates a wrapper object. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringTurns something in JSON into a result via an instance ofResult.static StringExecutesfunctionwithparamsand catches all occurring exceptions turning them into anExecutionException.static JsonResultWrapper.ResultresultFromJson(Object json) Turns something in JSON into aResult.static StringTurns aJsonResultWrapper.Resultinto JSON.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
MAPPER
-
func
-
listener
-
taskIdSupplier
-
-
Constructor Details
-
JsonResultWrapper
Creates a wrapper object.- Parameters:
func- a function that may throw an exception.
-
JsonResultWrapper
public JsonResultWrapper(JsonResultWrapper.ExceptionFunction func, JsonResultWrapper.OperationCompletedListener listener) Creates a wrapper object.- Parameters:
func- a function that may throw an exception.listener- optional operation completed listener
-
JsonResultWrapper
public JsonResultWrapper(JsonResultWrapper.ExceptionFunction func, Function<Object[], String> taskIdSupplier) Creates a wrapper object.- Parameters:
func- a function that may throw an exception.taskIdSupplier- optional task id to track viaTaskRegistry
-
JsonResultWrapper
public JsonResultWrapper(JsonResultWrapper.ExceptionFunction func, JsonResultWrapper.OperationCompletedListener listener, Function<Object[], String> taskIdSupplier) Creates a wrapper object.- Parameters:
func- a function that may throw an exception.listener- optional operation completed listenertaskIdSupplier- optional task id to track viaTaskRegistry
-
-
Method Details
-
apply
-
toJson
Turns aJsonResultWrapper.Resultinto JSON.- Parameters:
res- the result instance (may be null)- Returns:
- the JSON string or an empty string in case of problems/no address
-
resultFromJson
Turns something in JSON into aResult.- Parameters:
json- the JSON value, usually a String- Returns:
- the result instance
-
fromJson
Turns something in JSON into a result via an instance ofResult.- Parameters:
json- the JSON value, usually a String- Returns:
- the result value, may be null, e.g., if
jsonis null - Throws:
ExecutionException- if the parsedJsonResultWrapper.Resultrepresents an exception
-
fromJson
public static String fromJson(Function<Object[], Object> function, Object... params) throws ExecutionExceptionExecutesfunctionwithparamsand catches all occurring exceptions turning them into anExecutionException.- Parameters:
function- the function to be executed, must return aJsonResultWrapper.Resultas JSON, e.g., an instance ofJsonResultWrapperparams- the function parameters- Returns:
- the return value
- Throws:
ExecutionException- in case that function cannot be executed
-