ikrs.json
Class JSONString

java.lang.Object
  extended by ikrs.json.AbstractJSONValue
      extended by ikrs.json.JSONString
All Implemented Interfaces:
JSONValue

public class JSONString
extends AbstractJSONValue

This is the JSON string subclass.


Field Summary
 
Fields inherited from interface ikrs.json.JSONValue
FALSE, NULL, TRUE, TYPE_ARRAY, TYPE_BOOLEAN, TYPE_NULL, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
JSONString(java.lang.String string)
          Create a new JSON string.
 
Method Summary
 JSONArray asJSONArray()
          This method tries to convert this JSONValue into a JSONArray.
 JSONBoolean asJSONBoolean()
          This method tries to convert this JSONValue into a JSONBoolean.
 JSONNumber asJSONNumber()
          This method tries to convert this JSONValue into a JSONNumber.
 JSONString asJSONString()
          This method tries to convert this JSONValue into a JSONString.
 java.lang.String getString()
          Get the string from this JSON value.
 java.lang.String toString()
          Note: this method does not (!) return a valid JSON string value!
 void write(java.io.Writer writer)
          This method MUST write a valid JSON value to the passed writer.
static void writeJSON(java.io.Writer writer, java.lang.String string)
           
 
Methods inherited from class ikrs.json.AbstractJSONValue
asJSONObject, getArray, getBoolean, getNumber, getObject, getTypeName, isArray, isBoolean, isNull, isNumber, isObject, isString, isValidTypeID, toJSONString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSONString

public JSONString(java.lang.String string)
           throws java.lang.NullPointerException
Create a new JSON string.

Parameters:
string - The string value this JSON value should have.
Throws:
java.lang.NullPointerException
Method Detail

getString

public java.lang.String getString()
                           throws JSONException
Get the string from this JSON value.

Specified by:
getString in interface JSONValue
Overrides:
getString in class AbstractJSONValue
Returns:
The string value from this JSON value.
Throws:
JSONException - If this value does not represent a string.

asJSONBoolean

public JSONBoolean asJSONBoolean()
                          throws JSONException
This method tries to convert this JSONValue into a JSONBoolean. If that is not possible (because the contained value does not represent a boolean in any way) the method will throw an JSONException.

Specified by:
asJSONBoolean in interface JSONValue
Overrides:
asJSONBoolean in class AbstractJSONValue
Returns:
This JSON value as a JSON boolean.
Throws:
JSONException - If this value is not convertible to a boolean.

asJSONNumber

public JSONNumber asJSONNumber()
                        throws JSONException
This method tries to convert this JSONValue into a JSONNumber. If that is not possible (because the contained value does not represent a number in any way) the method will throw an JSONException.

Specified by:
asJSONNumber in interface JSONValue
Overrides:
asJSONNumber in class AbstractJSONValue
Returns:
This JSON value as a JSON number.
Throws:
JSONException - If this value is not convertible to a number.

asJSONString

public JSONString asJSONString()
                        throws JSONException
This method tries to convert this JSONValue into a JSONString. If that is not possible (because the contained value does not represent a string in any way) the method will throw an JSONException. Note: due to the fact that JSON is usually represented by a string EACH JSON VALUE SHOULD BE CONVERTIBLE TO A STRING.

Specified by:
asJSONString in interface JSONValue
Overrides:
asJSONString in class AbstractJSONValue
Returns:
This JSON value as a JSON string.
Throws:
JSONException - If this value is not convertible to a boolean.

asJSONArray

public JSONArray asJSONArray()
                      throws JSONException
This method tries to convert this JSONValue into a JSONArray. If that is not possible (because the contained value does not represent an array in any way) the method will throw an JSONException.

Specified by:
asJSONArray in interface JSONValue
Overrides:
asJSONArray in class AbstractJSONValue
Returns:
This JSON value as a JSON array.
Throws:
JSONException - If this value is not convertible to an array.

write

public void write(java.io.Writer writer)
           throws java.io.IOException
This method MUST write a valid JSON value to the passed writer.

Specified by:
write in interface JSONValue
Specified by:
write in class AbstractJSONValue
Parameters:
writer - The writer to write to.
Throws:
java.io.IOException - If any IO errors occur.

toString

public java.lang.String toString()
Note: this method does not (!) return a valid JSON string value!

Overrides:
toString in class java.lang.Object

writeJSON

public static void writeJSON(java.io.Writer writer,
                             java.lang.String string)
                      throws java.io.IOException
Throws:
java.io.IOException