Package io.milton.common
Class JsonResult
- java.lang.Object
-
- io.milton.common.JsonResult
-
public class JsonResult extends Object
Value object holding the result of some operation in a generic form which is suitable for outputting as JSON.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classJsonResult.FieldMessageRepresents a message (usually a validation error) pertaining to a field The field name is the name of the POST variable which caused the error
-
Field Summary
Fields Modifier and Type Field Description static StringCONTENT_TYPE
-
Constructor Summary
Constructors Constructor Description JsonResult()JsonResult(boolean status)JsonResult(boolean status, String message)JsonResult(boolean status, String message, String nextHref)JsonResult(boolean status, String nextHref, List<String> messages, List<JsonResult.FieldMessage> fieldMessages)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFieldMessage(String field, String message)static JsonResulterror(String description)static JsonResultfieldError(String field, String fieldMessage)ObjectgetData()Any JSON friendly objectList<JsonResult.FieldMessage>getFieldMessages()List of messages relating to specific fields.List<String>getMessages()Any messages which are not specific to certain fieldsStringgetNextHref()If an object was created this should be the href of that object.booleanisStatus()Flag to indicate success or failure of the operationstatic JsonResultreturnData(Object data)static JsonResultreturnData(String href, Object data)voidsetData(Object data)voidsetFieldMessages(List<JsonResult.FieldMessage> fieldMessages)voidsetMessages(List<String> messages)voidsetNextHref(String nextHref)voidsetStatus(boolean status)
-
-
-
Field Detail
-
CONTENT_TYPE
public static String CONTENT_TYPE
-
-
Method Detail
-
error
public static JsonResult error(String description)
-
fieldError
public static JsonResult fieldError(String field, String fieldMessage)
-
returnData
public static JsonResult returnData(String href, Object data)
-
returnData
public static JsonResult returnData(Object data)
-
isStatus
public boolean isStatus()
Flag to indicate success or failure of the operation- Returns:
- the status
-
setStatus
public void setStatus(boolean status)
- Parameters:
status- the status to set
-
getNextHref
public String getNextHref()
If an object was created this should be the href of that object. If the operation completed was part of a workflow then this should be the href of the next step in the workflow- Returns:
- the nextHref
-
setNextHref
public void setNextHref(String nextHref)
- Parameters:
nextHref- the nextHref to set
-
getMessages
public List<String> getMessages()
Any messages which are not specific to certain fields- Returns:
- the messages
-
setMessages
public void setMessages(List<String> messages)
- Parameters:
messages- the messages to set
-
getFieldMessages
public List<JsonResult.FieldMessage> getFieldMessages()
List of messages relating to specific fields. The field name must correspond to a POST variable name- Returns:
- the fieldMessages
-
setFieldMessages
public void setFieldMessages(List<JsonResult.FieldMessage> fieldMessages)
- Parameters:
fieldMessages- the fieldMessages to set
-
getData
public Object getData()
Any JSON friendly object- Returns:
-
setData
public void setData(Object data)
-
-