Generic value object representing the outcome of an operation - a status flag, human-readable messages, optional field-level validation messages and an arbitrary data payload - intended for serialisation to JSON as the response of a controller action or a GraalJS-exported service method. Provides fluent helper methods for building up messages and data attributes so callers can chain calls when constructing a response.


Properties

PropertyReturnsDescription
dataObjectArbitrary payload data returned with this result. Expected to be JSON friendly, such as a Map, List or primitive value. May be null if no data has been set.
fieldMessagesList<FieldMessage>Validation or error messages relating to specific fields, where each field name corresponds to a POST variable name. May be null or empty if no field messages have been added.
messagesList<String>General messages relating to this result that are not specific to any one field. May be null or empty if no general messages have been added.
nextHrefStringThe href to navigate to as a result of this operation. If an object was created this is the href of that object; if the operation completed a step in a workflow this is the href of the next step. May be null.
statusbooleanFlag indicating success or failure of the operation this result represents.

Methods

toMap() · dataAttribute(String key, Object value) · dataAttributes(Map<String,Object> attributes) · fieldMessage(String fieldName, String message) · message(String message) · addMessage(String s) · addFieldMessage(String field, String message) · writeWithNiceDates(OutputStream out) · write(OutputStream out) · isStatus() · setStatus(boolean status) · getNextHref() · setNextHref(String nextHref) · getMessages() · setMessages(List<String> messages) · getFieldMessages() · setFieldMessages(List<FieldMessage> fieldMessages) · getData() · setData(Object data)

toMap()

Returns: Map<String,Object>

Builds a plain, JSON-serialisable map of this result's status, nextHref, messages and field messages. The data property is deliberately left out because it is not known whether it is serialisable.

dataAttribute(String key, Object value)

Returns: JsonResult

Sets a name/value pair on this result's data object, creating the data object as a HashMap first if it is currently null. Throws if data already holds a value that is not a Map.

ParameterDescription
keythe attribute name to set on the data map
valuethe value to associate with the key

dataAttributes(Map<String,Object> attributes)

Returns: JsonResult

Calls dataAttribute for each entry in the given map, converting each value to a string first. Does nothing if attributes is null.

ParameterDescription
attributesthe name/value pairs to add to this result's data object

fieldMessage(String fieldName, String message)

Returns: JsonResult

Same as addFieldMessage but returns this to allow chaining.

ParameterDescription
fieldNamethe name of the POST variable the message relates to
messagethe validation or error message text

message(String message)

Returns: JsonResult

Same as addMessage but returns this to allow chaining.

ParameterDescription
messagethe message text to add

addMessage(String s)

Returns: void

Adds a message to the messages list, creating the list first if it does not already exist.

ParameterDescription
sthe message text to add

addFieldMessage(String field, String message)

Returns: void

Adds a FieldMessage to the field messages list, creating the list first if it does not already exist.

ParameterDescription
fieldthe name of the POST variable the message relates to
messagethe validation or error message text

writeWithNiceDates(OutputStream out)

Returns: void

Serialises this result as JSON to the given stream, writing any Date values as a formatted string rather than as a raw long.

ParameterDescription
outthe stream to write the JSON output to

write(OutputStream out)

Returns: void

Serialises this result as JSON to the given stream.

ParameterDescription
outthe stream to write the JSON output to

isStatus()

Returns: boolean

Flag indicating success or failure of the operation this result represents.

setStatus(boolean status)

Returns: void

Sets the success/failure flag for this result.

ParameterDescription
statustrue if the operation succeeded, false otherwise

getNextHref()

Returns: String

The href to navigate to as a result of this operation. If an object was created this is the href of that object; if the operation completed a step in a workflow this is the href of the next step. May be null.

setNextHref(String nextHref)

Returns: void

Sets the href to navigate to as a result of this operation.

ParameterDescription
nextHrefthe next href to navigate to

getMessages()

Returns: List<String>

General messages relating to this result that are not specific to any one field. May be null or empty if no general messages have been added.

setMessages(List<String> messages)

Returns: void

Replaces the list of general messages on this result.

ParameterDescription
messagesthe list of general messages to set

getFieldMessages()

Returns: List<FieldMessage>

Validation or error messages relating to specific fields, where each field name corresponds to a POST variable name. May be null or empty if no field messages have been added.

setFieldMessages(List<FieldMessage> fieldMessages)

Returns: void

Replaces the list of field-specific messages on this result.

ParameterDescription
fieldMessagesthe list of field messages to set

getData()

Returns: Object

Arbitrary payload data returned with this result. Expected to be JSON friendly, such as a Map, List or primitive value. May be null if no data has been set.

setData(Object data)

Returns: void

Sets the payload data returned with this result.

ParameterDescription
datathe payload data to set
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.