Class Response
- Direct Known Subclasses:
ClientFileUploadStatusResponse
This class provides the foundation for creating structured JSON responses that are sent
from the server to clients. All response types must extend this class and implement
the toJson() method to define their specific JSON structure.
Features:
- Unique response identification system
- Standardized JSON response generation
- Type-safe response hierarchy through inheritance
- Consistent response structure across all response types
Usage:
To create a custom response type, extend this class and implement the toJson() method:
public class CustomResponse extends Response {
public CustomResponse(String responseId) {
super(responseId);
}
@Override
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.put("id", getResponseId());
// Add custom JSON structure
return json;
}
}
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the unique identifier for this response.abstract JsonObjecttoJson()Generates and returns the JSON representation of this response.
-
Constructor Details
-
Response
Constructs a new Response with the specified response identifier.The response ID should uniquely identify the type of response being created and is used by clients to determine how to process the response data.
- Parameters:
responseId- the unique identifier for this response type (e.g., "update", "addition", "deletion")
-
-
Method Details
-
getResponseId
Returns the unique identifier for this response.This identifier is used to classify the response type and is typically included in the JSON representation of the response.
- Returns:
- the response identifier string
-
toJson
Generates and returns the JSON representation of this response.Subclasses must implement this method to define the specific JSON structure for their response type. The returned
JsonObjectshould contain all necessary data and properties that the client needs to process the response.- Returns:
- a
JsonObjectrepresenting the complete JSON structure of this response - Throws:
ElementException- if an error occurs during JSON generation
-