diff options
Diffstat (limited to 'src/main/java/de/torui/coflsky/commands/JsonStringCommand.java')
-rw-r--r-- | src/main/java/de/torui/coflsky/commands/JsonStringCommand.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java b/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java new file mode 100644 index 0000000..6bc22d8 --- /dev/null +++ b/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java @@ -0,0 +1,28 @@ +package de.torui.coflsky.commands; + +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +public class JsonStringCommand extends Command<String> { + + public JsonStringCommand(String type, String data) { + this.setType(CommandType.valueOf(type)); + this.setData(data); + } + + public JsonStringCommand() { + super(); + + } + + public JsonStringCommand(CommandType type, String data) { + super(type, data); + } + + public <T> Command<T> GetAs(TypeToken<T> type){ + T t = new GsonBuilder().create().fromJson(this.getData(),type.getType()); + Command<?> cmd = new Command<Object>(this.getType(), t); + + return (Command<T>) cmd; + } +} |