Package org.apache.sling.servlets.post
Class JakartaJSONResponse
java.lang.Object
org.apache.sling.servlets.post.AbstractJakartaPostResponse
org.apache.sling.servlets.post.JakartaJSONResponse
- All Implemented Interfaces:
JakartaPostResponse
The
JSONResponse
is an AbstractJakartaPostResponse
preparing
the response in JSON.- Since:
- 2.5.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.apache.sling.servlets.post.AbstractJakartaPostResponse
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doSend
(jakarta.servlet.http.HttpServletResponse response) getError()
Returns any recorded error ornull
getProperty
(String name) Returns the generic response property with the given name and type ornull
if no such property exists.void
Records a generic change of the giventype
with arguments.void
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.AbstractJakartaPostResponse
getLocation, getParentLocation, getPath, getProperty, getReferer, getStatusCode, getStatusMessage, isCreateRequest, isSafeReferer, isSuccessful, onCopied, onCreated, onDeleted, onModified, onMoved, send, setCreateRequest, setLocation, setParentLocation, setPath, setReferer, setStatus, setTitle
-
Field Details
-
RESPONSE_CONTENT_TYPE
- See Also:
-
-
Constructor Details
-
JakartaJSONResponse
public JakartaJSONResponse()
-
-
Method Details
-
onChange
Description copied from interface:JakartaPostResponse
Records a generic change of the giventype
with arguments.- Parameters:
type
- The type of the modificationarguments
- The arguments to the modifications
-
setError
Description copied from interface:JakartaPostResponse
Sets the recorded error causing the operation to fail.- Specified by:
setError
in interfaceJakartaPostResponse
- Overrides:
setError
in classAbstractJakartaPostResponse
- Parameters:
error
- the throwable
-
getError
Description copied from class:AbstractJakartaPostResponse
Returns any recorded error ornull
- Specified by:
getError
in interfaceJakartaPostResponse
- Overrides:
getError
in classAbstractJakartaPostResponse
- Returns:
- an error or
null
-
setProperty
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.- Overrides:
setProperty
in classAbstractJakartaPostResponse
- 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:
JakartaJSONResponse.JSONResponseException
- if the value is not usable
-
getProperty
Description copied from class:AbstractJakartaPostResponse
Returns the generic response property with the given name and type ornull
if no such property exists.- Overrides:
getProperty
in classAbstractJakartaPostResponse
- Parameters:
name
- the name of the response property- Returns:
- the requested property (might be null)
-
doSend
- Specified by:
doSend
in classAbstractJakartaPostResponse
- Throws:
IOException
-