PlotSquared/src/main/java/com/plotsquared/bukkit/chat/JsonString.java

55 lines
1.3 KiB
Java
Raw Normal View History

2015-07-30 19:24:01 +02:00
package com.plotsquared.bukkit.chat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
2015-07-30 16:25:16 +02:00
import com.google.gson.stream.JsonWriter;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
/**
* Represents a JSON string value.
* Writes by this object will not write name values nor begin/end objects in the JSON stream.
* All writes merely write the represented string value.
*/
2015-09-11 12:09:22 +02:00
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable
{
private final String _value;
public JsonString(final CharSequence value)
{
_value = value == null ? null : value.toString();
}
@Override
public void writeJson(final JsonWriter writer) throws IOException
{
writer.value(getValue());
}
public String getValue()
{
return _value;
}
@Override
public Map<String, Object> serialize()
{
final HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
theSingleValue.put("stringValue", _value);
return theSingleValue;
}
public static JsonString deserialize(final Map<String, Object> map)
{
return new JsonString(map.get("stringValue").toString());
}
@Override
public String toString()
{
return _value;
}
}