aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java
blob: a4ee15ed0d3917e58972de70a98995e1445a4d76 (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
29
30
package de.torui.coflsky.commands;

import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import de.torui.coflsky.network.WSClient;

public class JsonStringCommand extends Command<String> {
	
	public JsonStringCommand(String type, String data) {
		this.setType(WSClient.gson.fromJson(type, CommandType.class));
		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;
	}
}