Event { public static Event<?> fromJson(String json) throws IOException { return JSONUtil.toObject(json, new TypeReference<Event<?>>() {}); } Event(int eventId, Type type, long timestamp, T payload); private  Event(Type type, T payload);  Event(); int getId(); Type getType(); long getTimestamp(); T getPayload(); String toJson(); static Event<?> fromJson(String json); @SuppressWarnings("unchecked") static Event create(Type type, Object data); static void main(String[] args);  }
@Test public void testFromJson() throws IOException { String json = "{\n" + " \"type\" : \"JOB_STARTED\",\n" + " \"payload\" : {\n" + " \"name\" : \"scope-29\",\n" + " \"job\" : {\n" + " \"runtime\" : \"default\",\n" + " \"id\" : \"job_local_0001\",\n" + " \"aliases\" : [ \"A\", \"AA\", \"B\", \"C\" ],\n" + " \"features\" : [ \"GROUP_BY\", \"COMBINER\", \"MAP_PARTIALAGG\" ],\n" + " \"metrics\" : { \n" + " \"somemetrics\" : 111 \n" + " } \n " + " },\n" + " \"successorNames\" : [ ]\n" + " },\n" + " \"id\" : 1,\n" + " \"timestamp\" : 1373560988033\n" + "}"; Event event = Event.fromJson(json); Job job = ((DAGNode<Job>)event.getPayload()).getJob(); assertEquals("job_local_0001", job.getId()); assertEquals(111, job.getMetrics().get("somemetrics")); }