Package org.apache.sling.servlets.post
Class JSONResponse
- java.lang.Object
-
- org.apache.sling.servlets.post.AbstractPostResponse
-
- org.apache.sling.servlets.post.JSONResponse
-
- All Implemented Interfaces:
PostResponse
public class JSONResponse extends AbstractPostResponse
TheJSONResponse
is anAbstractPostResponse
preparing the response in JSON.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
JSONResponse.JSONResponseException
-
Field Summary
Fields Modifier and Type Field Description static String
RESPONSE_CONTENT_TYPE
-
Fields inherited from class org.apache.sling.servlets.post.AbstractPostResponse
PN_ERROR, PN_IS_CREATED, PN_LOCATION, PN_PARENT_LOCATION, PN_PATH, PN_REFERER, PN_STATUS_CODE, PN_STATUS_MESSAGE, PN_TITLE
-
-
Constructor Summary
Constructors Constructor Description JSONResponse()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Throwable
getError()
Returns any recorded error ornull
Object
getProperty(String name)
void
onChange(String type, String... arguments)
Records a generic change of the giventype
with arguments.void
setError(Throwable error)
Sets the recorded error causing the operation to fail.void
setProperty(String name, Object value)
This method accepts values that correspond to json primitives or otherwise assumes that the toString() of the value can be parsed as json.-
Methods inherited from class org.apache.sling.servlets.post.AbstractPostResponse
getLocation, getParentLocation, getPath, getReferer, getStatusCode, getStatusMessage, isCreateRequest, isSuccessful, onCopied, onCreated, onDeleted, onModified, onMoved, send, setCreateRequest, setLocation, setParentLocation, setPath, setReferer, setStatus, setTitle
-
-
-
-
Field Detail
-
RESPONSE_CONTENT_TYPE
public static final String RESPONSE_CONTENT_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
onChange
public void onChange(String type, String... arguments)
Description copied from interface:PostResponse
Records a generic change of the giventype
with arguments.- Parameters:
type
- The type of the modificationarguments
- The arguments to the modifications
-
setError
public void setError(Throwable error)
Description copied from interface:PostResponse
Sets the recorded error causing the operation to fail.- Specified by:
setError
in interfacePostResponse
- Overrides:
setError
in classAbstractPostResponse
- Parameters:
error
- the throwable
-
getError
public Throwable getError()
Description copied from class:AbstractPostResponse
Returns any recorded error ornull
- Specified by:
getError
in interfacePostResponse
- Overrides:
getError
in classAbstractPostResponse
- Returns:
- an error or
null
-
setProperty
public void setProperty(String name, Object value)
This method accepts values that correspond to json primitives or otherwise assumes that the toString() of the value can be parsed as json. If neither is the case it will throw an Exception. Assuming the above holds, it will put the value as json directly into the json value part of the response.- Parameters:
name
- name of the propertyvalue
- value of the property - either of type {String, Boolean, Number, null} or the toString() is parseable as json- Throws:
JSONResponse.JSONResponseException
- if the value is not usable
-
-