mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 23:26:45 +01:00
8e7e5dcb25
Signed-off-by: MattBDev <mattbdev@outlook.com>
48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
package com.plotsquared.bukkit.chat;
|
|
|
|
import com.google.gson.stream.JsonWriter;
|
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|
|
|
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.
|
|
*/
|
|
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
|
|
|
|
private String _value;
|
|
|
|
public JsonString(CharSequence value) {
|
|
_value = value == null ? null : value.toString();
|
|
}
|
|
|
|
@Override
|
|
public void writeJson(JsonWriter writer) throws IOException {
|
|
writer.value(getValue());
|
|
}
|
|
|
|
public String getValue() {
|
|
return _value;
|
|
}
|
|
|
|
public Map<String, Object> serialize() {
|
|
HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
|
|
theSingleValue.put("stringValue", _value);
|
|
return theSingleValue;
|
|
}
|
|
|
|
public static JsonString deserialize(Map<String, Object> map) {
|
|
return new JsonString(map.get("stringValue").toString());
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return _value;
|
|
}
|
|
|
|
}
|