2015-07-30 19:24:01 +02:00
|
|
|
package com.plotsquared.bukkit.chat;
|
2015-06-23 23:44:44 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-06-23 23:44:44 +02:00
|
|
|
/**
|
|
|
|
* 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-13 06:04:31 +02:00
|
|
|
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
|
|
|
|
|
2015-09-11 12:09:22 +02:00
|
|
|
private final String _value;
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public JsonString(final CharSequence value) {
|
2015-09-11 12:09:22 +02:00
|
|
|
_value = value == null ? null : value.toString();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-09-11 12:09:22 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public void writeJson(final JsonWriter writer) throws IOException {
|
2015-09-11 12:09:22 +02:00
|
|
|
writer.value(getValue());
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public String getValue() {
|
2015-09-11 12:09:22 +02:00
|
|
|
return _value;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-09-11 12:09:22 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public Map<String, Object> serialize() {
|
2015-09-11 12:09:22 +02:00
|
|
|
final HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
|
|
|
|
theSingleValue.put("stringValue", _value);
|
|
|
|
return theSingleValue;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public static JsonString deserialize(final Map<String, Object> map) {
|
2015-09-11 12:09:22 +02:00
|
|
|
return new JsonString(map.get("stringValue").toString());
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
2015-09-11 12:09:22 +02:00
|
|
|
@Override
|
2015-09-13 06:04:31 +02:00
|
|
|
public String toString() {
|
2015-09-11 12:09:22 +02:00
|
|
|
return _value;
|
|
|
|
}
|
2015-06-23 23:44:44 +02:00
|
|
|
}
|