Class Result<T>

java.lang.Object
net.solarnetwork.domain.Result<T>
Type Parameters:
T - the object type

public class Result<T> extends Object
A simple service result envelope object.
Version:
1.2
Author:
matt
  • Constructor Details

    • Result

      public Result()
      Construct a successful response with no data.
    • Result

      public Result(T data)
      Construct a successful response with just data.
      Parameters:
      data - the data
    • Result

      public Result(Boolean success, String code, String message, T data)
      Constructor.
      Parameters:
      success - flag of success
      code - optional code, e.g. error code
      message - optional descriptive message
      data - optional data in the response
    • Result

      public Result(Boolean success, String code, String message, List<Result.ErrorDetail> errors, T data)
      Constructor.
      Parameters:
      success - flag of success
      code - optional code, e.g. error code
      message - optional descriptive message
      errors - optional errors
      data - optional data in the response
      Since:
      1.2
  • Method Details

    • result

      public static <V> Result<V> result(V data)
      Helper method to construct instance using generic return type inference.

      This is an alias for success(Object). If you import this static method, then in your code you can write return result(myData) instead of new Result&lt;Object&gt;(myData).

      Type Parameters:
      V - the result type
      Parameters:
      data - the data
      Returns:
      the result with success set to true
      See Also:
    • success

      public static <V> Result<V> success(V data)
      Helper method to construct a success instance using generic return type inference.

      If you import this static method, then in your code you can write return success(myData) instead of new Result&lt;Object&gt;(myData).

      Type Parameters:
      V - the result type
      Returns:
      the result with success set to true
      Since:
      1.2
    • success

      public static <V> Result<V> success()
      Helper method to construct a success instance using generic return type inference.
      Type Parameters:
      V - the result type
      Returns:
      the result with success set to true
      Since:
      1.2
    • error

      public static <V> Result<V> error()
      Helper method to construct an error instance using generic return type inference.
      Type Parameters:
      V - the result type
      Returns:
      the result
      Since:
      1.2
    • error

      public static <V> Result<V> error(String message, List<Result.ErrorDetail> errors)
      Helper method to construct an error instance using generic return type inference.
      Type Parameters:
      V - the result type
      Parameters:
      message - the message
      errors - the errors
      Returns:
      the result
      Since:
      1.2
    • error

      public static <V> Result<V> error(String code, String message, List<Result.ErrorDetail> errors)
      Helper method to construct an error instance using generic return type inference.
      Type Parameters:
      V - the result type
      Parameters:
      code - the code
      message - the message
      errors - the errors
      Returns:
      the result
      Since:
      1.2
    • error

      public static <V> Result<V> error(String code, String message, Result.ErrorDetail... errors)
      Helper method to construct an error instance using generic return type inference.
      Type Parameters:
      V - the result type
      Parameters:
      code - the code
      message - the message
      errors - the errors
      Returns:
      the result
      Since:
      1.2
    • getSuccess

      public Boolean getSuccess()
      Get the success indicator.
      Returns:
      the success indicator, or null if not known
    • getCode

      public String getCode()
      Get the code.
      Returns:
      the code, or null
    • getMessage

      public String getMessage()
      Get the message.
      Returns:
      the message, or null
    • getErrors

      public List<Result.ErrorDetail> getErrors()
      Get the error details.
      Returns:
      the error details, or null
    • getData

      public T getData()
      Get the data.
      Returns:
      the data, or null