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