Class EUA
java.lang.Object
fr.inria.rules.integraal.api.external.eua.EUA
Represents a standardized JSON-based response object intended for end-user communication.
The EUA (End User Answer) class wraps a JSON structure that contains:
result– a numeric status code (usually fromEUACode)message– a human-readable message or payloaddata– a nested JSON object for additional key-value data
This structure is useful for APIs, services, or UI-layer responses where a consistent, structured format is required for both humans and machines to interpret.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a key-value pair to the internaldatasection of the JSON response.getCode()Returns the enumerated result code stored in this EUA.org.json.JSONObjectgetData()Returns the data object stored in this EUA.getDataField(EUAData name) Returns a data field stored under the given key.Returns the human-readable message stored in this EUA.intReturns the numeric result code stored in this EUA.static voidTemporary entry point for development and internal testing purposes only.static EUABuilds anEUAobject from its corresponding JSON StringReturns the full JSON representation of this response as a string.toString()Returns the JSON string representation of this response.
-
Field Details
-
CODE_KEY
-
MESSAGE_KEY
-
DATA_KEY
-
-
Constructor Details
-
EUA
Constructs a newEUAresponse object.Initializes the internal JSON structure with a result code, a message intended for the end user, and an empty
dataobject to which key-value pairs can be added later.- Parameters:
code- anEUACodeinstance representing the result statusmessage- a human-readable message for the end user; must not benull- Throws:
NullPointerException- ifcodeormessageisnull
-
-
Method Details
-
getResult
public int getResult()Returns the numeric result code stored in this EUA.- Returns:
- the numeric result code
-
getCode
Returns the enumerated result code stored in this EUA.- Returns:
- the result code as an enum value
-
getMessage
Returns the human-readable message stored in this EUA.- Returns:
- the message
-
getData
public org.json.JSONObject getData()Returns the data object stored in this EUA.- Returns:
- the data object
-
getDataField
-
add
Adds a key-value pair to the internaldatasection of the JSON response. If the value isnull, it is converted toJSONObject.NULL.- Parameters:
key- the name of the field to addvalue- the value to associate with the key; may benull- Returns:
- this EUA instance
- Throws:
org.json.JSONException- if the value is of an unsupported type (e.g.,NaN,Infinity)NullPointerException- if thekeyisnull
-
toJsonString
Returns the full JSON representation of this response as a string.- Returns:
- the serialized JSON string
-
toString
Returns the JSON string representation of this response. Equivalent totoJsonString(). -
parse
Builds anEUAobject from its corresponding JSON String- Parameters:
jsonString- a JSON String representation of anEUAobject- Returns:
- the parsed EUA object
- Throws:
org.json.JSONException- If the string is not valid JSON or if required keys are missingIllegalArgumentException- If the result code is unknown
-
main
Temporary entry point for development and internal testing purposes only.This method is intended to facilitate quick, manual checks during development. It should not be used in production code, nor relied upon for automated testing.
May be modified or removed at any time without notice.
- Parameters:
args- command-line arguments (not used)
-