package uk.co.vurt.taskhelper.domain;

import uk.co.vurt.hakken.domain.job.JobDefinition;
import uk.co.vurt.hakken.domain.task.TaskDefinition;

import com.google.gson.Gson;

public class JSONUtil {

	Gson gson;
	
	private JSONUtil(){
		gson = new Gson();
	}
	
	private static class JSONUtilHolder {
		public static final JSONUtil INSTANCE = new JSONUtil();
	}
	
	public static JSONUtil getInstance(){
		return JSONUtilHolder.INSTANCE;
	}
	
	public String toJson(Object pojo){
		return gson.toJson(pojo);
	}
	
	public TaskDefinition parseTaskDefinition(String json){
		return gson.fromJson(json, TaskDefinition.class);
	}
	
	public JobDefinition parseJobDefinition(String json){
		return gson.fromJson(json, JobDefinition.class);
	}
	
}

@@ -28,24 +28,79 @@
 er.domain;%0A%0A
+import java.lang.reflect.Type;%0Aimport java.util.Date;%0A%0A
 import uk.co
@@ -220,16 +220,223 @@
 on.Gson;
+%0Aimport com.google.gson.GsonBuilder;%0Aimport com.google.gson.JsonDeserializationContext;%0Aimport com.google.gson.JsonDeserializer;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonParseException;
 %0A%0Apublic
@@ -495,23 +495,351 @@
 %7B%0A%09%09
-gson = new Gson
+GsonBuilder builder = new GsonBuilder();%0A%09%09builder.registerTypeAdapter(Date.class, new JsonDeserializer%3CDate%3E() %7B%0A%0A%09%09%09public Date deserialize(JsonElement json, Type typeOfT,%0A%09%09%09%09%09JsonDeserializationContext context)%0A%09%09%09%09%09throws JsonParseException %7B%0A%09%09%09%09return new Date(json.getAsJsonPrimitive().getAsLong()); %0A%09%09%09%7D%0A%09%09%7D);%0A%09%09gson = builder.create
 ();%0A

modify JSON parse to retrieve dates as longs