*
* @throws JSONException Thrown on IO errors during serialization.
*/
public String write(int indentDepth) throws JSONException {
Serializer serializer;
JSON4JStringWriter writer = new JSON4JStringWriter();
if (indentDepth < 1) {
indentDepth = 0;
} else if (indentDepth > 8) {
indentDepth = 9;
}
if (indentDepth > 0) {
serializer = new SerializerVerbose(writer, indentDepth);
} else {
serializer = new Serializer(writer);
}
try {
serializer.writeArray(this).flush();
} catch (IOException iox) {
JSONException jex = new JSONException("Error occurred during input read.");
jex.setCause(iox);
throw jex;
}
return writer.toString();
}