List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:org.apache.tajo.datum.json.DatumAdapter.java
License:Apache License
@Override public Datum deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String className = jsonObject.get("classname").getAsJsonPrimitive().getAsString(); Class clazz;//from w ww . ja v a 2 s . com try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { e.printStackTrace(); throw new JsonParseException(e); } return context.deserialize(jsonObject.get("property"), clazz); }
From source file:org.apache.tajo.engine.json.EvalNodeAdapter.java
License:Apache License
@Override public EvalNode deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String nodeName = jsonObject.get("type").getAsString(); Class clazz = EvalType.valueOf(nodeName).getBaseClass(); return ctx.deserialize(jsonObject.get("body"), clazz); }
From source file:org.apache.tajo.engine.json.LogicalNodeAdapter.java
License:Apache License
@Override public LogicalNode deserialize(JsonElement src, Type type, JsonDeserializationContext ctx) throws JsonParseException { JsonObject jsonObject = src.getAsJsonObject(); String nodeName = jsonObject.get("type").getAsString(); Class clazz = NodeType.valueOf(nodeName).getBaseClass(); return ctx.deserialize(jsonObject.get("body"), clazz); }
From source file:org.apache.tajo.json.DatumAdapter.java
License:Apache License
@Override public Datum deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String typeName = CommonGsonHelper.getOrDie(jsonObject, "type").getAsString(); TajoDataTypes.Type type = TajoDataTypes.Type.valueOf(typeName); switch (type) { case DATE://from ww w .j a v a 2 s.co m return new DateDatum(CommonGsonHelper.getOrDie(jsonObject, "value").getAsInt()); case TIME: return new TimeDatum(CommonGsonHelper.getOrDie(jsonObject, "value").getAsLong()); case TIMESTAMP: return new TimestampDatum(CommonGsonHelper.getOrDie(jsonObject, "value").getAsLong()); case INTERVAL: String[] values = CommonGsonHelper.getOrDie(jsonObject, "value").getAsString().split(","); return new IntervalDatum(Integer.parseInt(values[0]), Long.parseLong(values[1])); default: return context.deserialize(CommonGsonHelper.getOrDie(jsonObject, "body"), DatumFactory.getDatumClass(TajoDataTypes.Type.valueOf(typeName))); } }
From source file:org.apache.tajo.plan.serder.EvalNodeAdapter.java
License:Apache License
@Override public EvalNode deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String nodeName = CommonGsonHelper.getOrDie(jsonObject, "type").getAsString(); Class clazz = EvalType.valueOf(nodeName).getBaseClass(); return ctx.deserialize(jsonObject.get("body"), clazz); }
From source file:org.apache.tajo.plan.serder.LogicalNodeAdapter.java
License:Apache License
@Override public LogicalNode deserialize(JsonElement src, Type type, JsonDeserializationContext ctx) throws JsonParseException { JsonObject jsonObject = src.getAsJsonObject(); String nodeName = CommonGsonHelper.getOrDie(jsonObject, "type").getAsString(); Class clazz = NodeType.valueOf(nodeName).getBaseClass(); return ctx.deserialize(jsonObject.get("body"), clazz); }
From source file:org.apache.twill.internal.json.JvmOptionsCodec.java
License:Apache License
@Override public JvmOptions deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String extraOptions = context.deserialize(jsonObj.get("extraOptions"), String.class); JvmOptions.DebugOptions debugOptions = context.deserialize(jsonObj.get("debugOptions"), JvmOptions.DebugOptions.class); return new JvmOptions(extraOptions, debugOptions); }
From source file:org.apache.twill.internal.json.LogEntryDecoder.java
License:Apache License
@Override public LogEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.isJsonObject()) { return null; }// w w w .j a v a 2 s . c o m JsonObject jsonObj = json.getAsJsonObject(); final String name = JsonUtils.getAsString(jsonObj, "name"); final String host = JsonUtils.getAsString(jsonObj, "host"); final long timestamp = JsonUtils.getAsLong(jsonObj, "timestamp", 0); final LogEntry.Level logLevel = LogEntry.Level.valueOf(JsonUtils.getAsString(jsonObj, "level")); final String className = JsonUtils.getAsString(jsonObj, "className"); final String method = JsonUtils.getAsString(jsonObj, "method"); final String file = JsonUtils.getAsString(jsonObj, "file"); final String line = JsonUtils.getAsString(jsonObj, "line"); final String thread = JsonUtils.getAsString(jsonObj, "thread"); final String message = JsonUtils.getAsString(jsonObj, "message"); final String runnableName = JsonUtils.getAsString(jsonObj, "runnableName"); final LogThrowable logThrowable = context.deserialize(jsonObj.get("throwable"), LogThrowable.class); return new LogEntry() { @Override public String getLoggerName() { return name; } @Override public String getHost() { return host; } @Override public long getTimestamp() { return timestamp; } @Override public Level getLogLevel() { return logLevel; } @Override public String getSourceClassName() { return className; } @Override public String getSourceMethodName() { return method; } @Override public String getFileName() { return file; } @Override public int getLineNumber() { if (line.equals("?")) { return -1; } else { return Integer.parseInt(line); } } @Override public String getThreadName() { return thread; } @Override public String getMessage() { return message; } @Override public String getRunnableName() { return runnableName; } @Override public LogThrowable getThrowable() { return logThrowable; } @Override public StackTraceElement[] getStackTraces() { LogThrowable throwable = getThrowable(); return (throwable == null) ? EMPTY_STACK_TRACES : throwable.getStackTraces(); } }; }
From source file:org.apache.twill.internal.json.LogThrowableCodec.java
License:Apache License
@Override public LogThrowable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return context.deserialize(json, DefaultLogThrowable.class); }
From source file:org.apache.twill.internal.json.ResourceReportCodec.java
License:Apache License
@Override public ResourceReport deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String appMasterId = jsonObj.get("appMasterId").getAsString(); TwillRunResources masterResources = context.deserialize(jsonObj.get("appMasterResources"), TwillRunResources.class); Map<String, Collection<TwillRunResources>> resources = context.deserialize(jsonObj.get("runnableResources"), new TypeToken<Map<String, Collection<TwillRunResources>>>() { }.getType());//from w ww. java2 s. c om List<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<List<String>>() { }.getType()); return new DefaultResourceReport(appMasterId, masterResources, resources, services); }