List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:org.apache.gobblin.runtime.spec_serde.FlowSpecSerializer.java
License:Apache License
@Override public JsonElement serialize(FlowSpec src, Type typeOfSrc, JsonSerializationContext context) { JsonObject flowSpecJson = new JsonObject(); flowSpecJson.add(FLOW_SPEC_URI_KEY, context.serialize(src.getUri())); flowSpecJson.add(FLOW_SPEC_VERSION_KEY, context.serialize(src.getVersion())); flowSpecJson.add(FLOW_SPEC_DESCRIPTION_KEY, context.serialize(src.getDescription())); flowSpecJson.add(FLOW_SPEC_CONFIG_KEY, context.serialize(src.getConfig().root().render(ConfigRenderOptions.concise()))); StringWriter writer = new StringWriter(); try {/* w w w . j a v a 2 s . c o m*/ src.getConfigAsProperties().store(writer, ""); } catch (IOException e) { throw new JsonParseException(e); } flowSpecJson.add(FLOW_SPEC_CONFIG_AS_PROPERTIES_KEY, context.serialize(writer.getBuffer().toString())); JsonArray templateURIs = new JsonArray(); if (src.getTemplateURIs().isPresent()) { for (URI templateURI : src.getTemplateURIs().get()) { templateURIs.add(context.serialize(templateURI)); } } flowSpecJson.add(FLOW_SPEC_TEMPLATE_URIS_KEY, templateURIs); JsonArray childSpecs = new JsonArray(); if (src.getChildSpecs().isPresent()) { for (Spec spec : src.getChildSpecs().get()) { childSpecs.add(context.serialize(spec)); } } flowSpecJson.add(FLOW_SPEC_CHILD_SPECS_KEY, childSpecs); return flowSpecJson; }
From source file:org.apache.tajo.catalog.json.FunctionAdapter.java
License:Apache License
@Override public JsonElement serialize(Function src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); String className = src.getClass().getName(); jsonObj.addProperty("class", className); JsonElement jsonElem = context.serialize(src); jsonObj.add("body", jsonElem); return jsonObj; }
From source file:org.apache.tajo.catalog.json.SchemaAdapter.java
License:Apache License
@Override public JsonElement serialize(Schema src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("version", src instanceof SchemaLegacy ? "1" : "2"); JsonElement jsonElem = context.serialize(src); jsonObj.add("body", jsonElem); return jsonObj; }
From source file:org.apache.tajo.catalog.json.TableDescAdapter.java
License:Apache License
@Override public JsonElement serialize(TableDesc src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); String className = src.getClass().getCanonicalName(); jsonObj.addProperty("classname", className); if (src.getClass().getSimpleName().equals("TableDescImpl")) { src.initFromProto();//from w w w .j a v a2 s. co m } JsonElement jsonElem = context.serialize(src); jsonObj.add("property", jsonElem); return jsonObj; }
From source file:org.apache.tajo.datum.json.DatumAdapter.java
License:Apache License
@Override public JsonElement serialize(Datum src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); String className = src.getClass().getCanonicalName(); jsonObj.addProperty("classname", className); JsonElement jsonElem = context.serialize(src); jsonObj.add("property", jsonElem); return jsonObj; }
From source file:org.apache.tajo.engine.json.EvalNodeAdapter.java
License:Apache License
@Override public JsonElement serialize(EvalNode evalNode, Type type, JsonSerializationContext ctx) { JsonObject json = new JsonObject(); json.addProperty("type", evalNode.getType().name()); json.add("body", ctx.serialize(evalNode)); return json;//from w ww . j a v a 2 s.co m }
From source file:org.apache.tajo.engine.json.LogicalNodeAdapter.java
License:Apache License
@Override public JsonElement serialize(LogicalNode src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("type", src.getType().name()); json.add("body", context.serialize(src)); return json;/*from w w w .ja v a2 s .c o m*/ }
From source file:org.apache.tajo.json.DatumAdapter.java
License:Apache License
@Override public JsonElement serialize(Datum src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("type", src.type().name()); switch (src.type()) { case DATE:/* ww w . j a va 2s.co m*/ jsonObj.addProperty("value", src.asInt4()); break; case TIME: jsonObj.addProperty("value", src.asInt8()); break; case TIMESTAMP: jsonObj.addProperty("value", src.asInt8()); break; case INTERVAL: IntervalDatum interval = (IntervalDatum) src; jsonObj.addProperty("value", interval.getMonths() + "," + interval.getMilliSeconds()); break; default: jsonObj.add("body", context.serialize(src)); } return jsonObj; }
From source file:org.apache.twill.internal.json.JvmOptionsCodec.java
License:Apache License
@Override public JsonElement serialize(JvmOptions jvmOptions, Type type, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.add("extraOptions", context.serialize(jvmOptions.getExtraOptions())); json.add("debugOptions", context.serialize(jvmOptions.getDebugOptions())); return json;//from www . j a va 2s. com }
From source file:org.civilian.text.keys.serialize.KeyListSerializer.java
License:Open Source License
/** * Serializes the KeyList.// w w w . j a v a 2s.c o m */ @Override public JsonElement serialize(KeyList<?> keyList, Type typeOfSrc, JsonSerializationContext context) { JsonArray array = new JsonArray(); int n = keyList.size(); for (int i = 0; i < n; i++) { String text = keyList.getText(i); Object value = keyList.getValue(i); JsonObject element = new JsonObject(); element.addProperty("text", text); element.add("value", context.serialize(value)); array.add(element); } return array; }