Class ApiEnvelope<T>
java.lang.Object
neqsim.mcp.model.ApiEnvelope<T>
- Type Parameters:
T- the type of the data payload @author Even Solbraa @version 1.0
Standard API envelope for all MCP runner responses.
Wraps a typed result payload with status, warnings, and errors in a consistent format. This
provides a dual interface — call toJson() for the string-based MCP protocol, or use
getData() for typed Java access.
Success envelope:
{ "status": "success", "data": { ... }, "warnings": [] }
Error envelope:
{ "status": "error", "errors": [{"severity": "error", "code": "...", "message":
"..."}], "warnings": [] } -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateApiEnvelope(String status, T data, List<DiagnosticIssue> errors, List<String> warnings) Private constructor — use factory methods. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddWarning(String warning) Adds a warning to this envelope.static <T> ApiEnvelope<T> Creates an error envelope with a single issue.static <T> ApiEnvelope<T> errors(List<DiagnosticIssue> issues) Creates an error envelope with multiple issues.getData()Gets the data payload.Gets the error list.Gets the status string.Gets the warning list.booleanReturns true if this is a success envelope.static <T> ApiEnvelope<T> success(T data) Creates a success envelope with the given data.static <T> ApiEnvelope<T> Creates a success envelope with data and warnings.toJson()Converts this envelope to a JSON string.
-
Field Details
-
GSON
private static final com.google.gson.Gson GSON -
status
-
data
-
errors
-
warnings
-
-
Constructor Details
-
ApiEnvelope
-
-
Method Details
-
success
Creates a success envelope with the given data.- Type Parameters:
T- the payload type- Parameters:
data- the result payload- Returns:
- the success envelope
-
success
Creates a success envelope with data and warnings.- Type Parameters:
T- the payload type- Parameters:
data- the result payloadwarnings- the warning messages- Returns:
- the success envelope
-
error
Creates an error envelope with a single issue.- Type Parameters:
T- the payload type- Parameters:
code- the error codemessage- the error messageremediation- the fix suggestion- Returns:
- the error envelope
-
errors
Creates an error envelope with multiple issues.- Type Parameters:
T- the payload type- Parameters:
issues- the diagnostic issues- Returns:
- the error envelope
-
getStatus
-
isSuccess
public boolean isSuccess()Returns true if this is a success envelope.- Returns:
- true if status is "success"
-
getData
-
getErrors
-
getWarnings
-
addWarning
Adds a warning to this envelope.- Parameters:
warning- the warning message
-
toJson
-