aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java
blob: 6bc22d855cf3ce14acf8b532b159fc24b21cd2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
	}
}