Package com.iizix.ws.engine.json
Class JSONReply
java.lang.Object
com.iizix.ws.engine.json.JSONReply
- All Implemented Interfaces:
IReplyContent
Class for a JSON reply.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionConstructor.JSONReply
(JSONObject object) Constructor when recreating the JSON document.Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if formatting the output is supported.Formats the URLConnection HTTP headers reply into a String.Gets the accepted contents.Gets the format description.getElementFromPath
(String path) Gets an Object with specified path.Gets the JSON data.getRawOutput
(boolean doFormat) Gets the raw text data from the reply.boolean
Checks if a content type is handled by this reply.void
readReply
(RESTfulReply reply, String data) Called to format the request for this reply content, i.e.
Constructor Details
JSONReply
public JSONReply()Constructor.JSONReply
Constructor when recreating the JSON document.- Parameters:
object
- The JSON document object.
Method Details
getAcceptedContent
Gets the accepted contents.- Specified by:
getAcceptedContent
in interfaceIReplyContent
- Returns:
- The String "application/json".
isHandled
Checks if a content type is handled by this reply.- Specified by:
isHandled
in interfaceIReplyContent
- Parameters:
type
- The content type from the HTTP header "Content-Type", without "charset". The type is in lower case.- Returns:
- true if handled, false otherwise.
readReply
Called to format the request for this reply content, i.e. the accepted content.- Specified by:
readReply
in interfaceIReplyContent
- Parameters:
reply
- The reply instance.data
- The String data from the reply.- Throws:
IOException
- For I/O errors.
getJSONData
Gets the JSON data.- Returns:
- The JSON object.
canFormat
public boolean canFormat()Checks if formatting the output is supported.- Specified by:
canFormat
in interfaceIReplyContent
- Returns:
- true If formatting is supported.
getDescription
Gets the format description.- Specified by:
getDescription
in interfaceIReplyContent
- Returns:
- The description string.
formatHTTPReply
Formats the URLConnection HTTP headers reply into a String.- Specified by:
formatHTTPReply
in interfaceIReplyContent
- Returns:
- The formatted HTML reply string.
getRawOutput
Gets the raw text data from the reply.- Specified by:
getRawOutput
in interfaceIReplyContent
- Parameters:
doFormat
- Flag to format the output (used for JSON and XML).- Returns:
- The String of the reply, or null if an exception occurred.
getElementFromPath
Gets an Object with specified path. This Object could be one of:- Boolean
- Double
- String
- JSONObject
- JSONArray
- JSONObject.NULL
- Parameters:
path
- The path to look-up.- Returns:
- The element found, or null if not found.