de.hpi.fgis.dude.util.data.json
Class JsonString

java.lang.Object
  extended by de.hpi.fgis.dude.util.data.json.JsonString
All Implemented Interfaces:
AutoJsonable, JsonAtomic, JsonValue, Jsonable, Comparable<JsonValue>

public class JsonString
extends Object
implements JsonAtomic

JsonString represents a Json-convertible String.

Author:
Matthias Pohl

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.hpi.fgis.dude.util.data.json.JsonValue
JsonValue.JsonType
 
Constructor Summary
JsonString()
          Initializes an empty Json-convertible String.
JsonString(String value)
          Initializes a new Json-convertible String.
 
Method Summary
 int compareTo(JsonValue other)
          Compares the current instance with the passed JsonValue.
static JsonString createJsonString(String jsonCode)
          Creates a JsonString instance based on the passed Json code.
 boolean equals(Object obj)
           
 void fromJson(DuDeJsonParser<?> jsonParser)
          Initializes the current instance using the passed DuDeJsonParser.
 String getStringValue()
          Returns the actual value converted into a String.
 JsonValue.JsonType getType()
          Returns JsonType.String.
 int hashCode()
           
static String jsonize(String str)
          Converts the passed String into its Json representation.
 int size()
          Returns 1 since JsonString is an atomic value.
 void toJson(DuDeJsonGenerator jsonGenerator)
          Generates the Json code using the passed DuDeJsonGenerator.
 String toString()
          Returns the actual String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonString

public JsonString()
Initializes an empty Json-convertible String.


JsonString

public JsonString(String value)
Initializes a new Json-convertible String.

Parameters:
value - The actual String value.
Method Detail

createJsonString

public static JsonString createJsonString(String jsonCode)
                                   throws ParseException
Creates a JsonString instance based on the passed Json code.

Parameters:
jsonCode - The code that shall be converted into a JsonString
Returns:
The newly created JsonString.
Throws:
ParseException - If the passed Json code cannot be converted into a JsonString.

getType

public JsonValue.JsonType getType()
Returns JsonType.String.

Specified by:
getType in interface JsonValue
Returns:
The type of the current instance.
See Also:
JsonValue.getType()

jsonize

public static String jsonize(String str)
Converts the passed String into its Json representation.

Parameters:
str - The String that shall be converted.
Returns:
The Json representation of the passed String.

getStringValue

public String getStringValue()
Description copied from interface: JsonAtomic
Returns the actual value converted into a String. This method should be preferred in contrast to #toString().

Specified by:
getStringValue in interface JsonAtomic
Returns:
The actual value converted into a String.

toString

public String toString()
Returns the actual String.

Overrides:
toString in class Object
See Also:
Object.toString()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

size

public int size()
Returns 1 since JsonString is an atomic value.

Specified by:
size in interface JsonValue
Returns:
The number of concrete Java objects that are collected by the current instance.
See Also:
JsonValue.size()

compareTo

public int compareTo(JsonValue other)
Description copied from interface: JsonValue
Compares the current instance with the passed JsonValue. Instances of different JsonValue.JsonTypes are ordered lexicographically except for JsonValue.JsonType.Null. The above mentioned requirements define the following order: null == JsonValue.JsonType.Null < JsonValue.JsonType.Array < JsonValue.JsonType.Boolean < JsonValue.JsonType.Number < JsonValue.JsonType.Record < JsonValue.JsonType.String.

Specified by:
compareTo in interface JsonValue
Specified by:
compareTo in interface Comparable<JsonValue>
See Also:
Comparable.compareTo(Object)

toJson

public void toJson(DuDeJsonGenerator jsonGenerator)
            throws org.codehaus.jackson.JsonGenerationException,
                   IOException
Description copied from interface: Jsonable
Generates the Json code using the passed DuDeJsonGenerator.

Specified by:
toJson in interface Jsonable
Parameters:
jsonGenerator - The DuDeJsonGenerator that is used internally.
Throws:
org.codehaus.jackson.JsonGenerationException - If an error occurs while generating the Json syntax.
IOException - If an error occurs while writing to the output.

fromJson

public void fromJson(DuDeJsonParser<?> jsonParser)
              throws org.codehaus.jackson.JsonParseException,
                     IOException
Description copied from interface: Jsonable
Initializes the current instance using the passed DuDeJsonParser.

Specified by:
fromJson in interface Jsonable
Parameters:
jsonParser - The parser that is used for extracting the data out of the Json.
Throws:
org.codehaus.jackson.JsonParseException - If an error occurs while parsing the Json.
IOException - If an error occurs while reading from the stream.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.