List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:co.cask.cdap.proto.codec.SparkSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(SparkSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("mainClassName", new JsonPrimitive(src.getMainClassName())); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); if (src.getDriverResources() != null) { jsonObj.add("driverResources", context.serialize(src.getDriverResources())); }// w w w.ja v a2 s .com if (src.getExecutorResources() != null) { jsonObj.add("executorResources", context.serialize(src.getExecutorResources())); } return jsonObj; }
From source file:co.cask.cdap.proto.codec.WorkflowNodeCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowNode src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src); }
From source file:co.cask.cdap.proto.codec.WorkflowTokenDetailCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowTokenDetail src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getTokenData()); }
From source file:co.cask.cdap.proto.codec.WorkflowTokenNodeDetailCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowTokenNodeDetail src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getTokenDataAtNode()); }
From source file:co.cask.cdap.template.etl.common.StructuredRecordSerializer.java
License:Apache License
@Override public JsonElement serialize(StructuredRecord src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); for (Schema.Field field : src.getSchema().getFields()) { obj.add(field.getName(), context.serialize(src.get(field.getName()))); }/*from w ww . ja v a2 s . c om*/ return obj; }
From source file:com.aliakseipilko.flightdutytracker.utils.FlightSerialiser.java
License:Open Source License
@Override public JsonElement serialize(final Flight src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); jsonObject.add("id", context.serialize(src.getId())); jsonObject.addProperty("departureIATACode", src.getDepartureIATACode()); jsonObject.addProperty("departureICAOCode", src.getDepartureICAOCode()); jsonObject.addProperty("arrivalIATACode", src.getArrivalIATACode()); jsonObject.addProperty("arrivalICAOCode", src.getArrivalICAOCode()); jsonObject.add("startDutyTime", context.serialize(src.getStartDutyTime())); jsonObject.add("endDutyTime", context.serialize(src.getEndDutyTime())); jsonObject.add("startFlightTime", context.serialize(src.getStartFlightTime())); jsonObject.add("endFlightTime", context.serialize(src.getEndFlightTime())); jsonObject.addProperty("acType", src.getAcType()); jsonObject.addProperty("flightNumber", src.getFlightNumber()); return jsonObject; }
From source file:com.arcbees.vcs.util.PolymorphicTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) { JsonObject retValue = new JsonObject(); String className = src.getClass().getCanonicalName(); retValue.addProperty(CLASSNAME, className); JsonElement jsonElement = context.serialize(src); retValue.add(VALUE, jsonElement);//from w ww . j av a 2 s. c om return retValue; }
From source file:com.bccriskadvisory.link.rest.gson.OptionalAdapter.java
License:Apache License
@Override public JsonElement serialize(Optional<T> src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.orElse(null)); }
From source file:com.caris.oscarexchange4j.util.serializers.ThemeSerializer.java
License:Apache License
@Override public JsonElement serialize(Theme src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); obj.add("id", context.serialize(src.getId())); if (src.getName() != null) obj.add("name", context.serialize(src.getName())); if (src.getCovers() != null) obj.add("covers", context.serialize(src.getCovers())); if (src.getLayers() != null) obj.add("layers", context.serialize(src.getLayers())); obj.add("displayOrder", context.serialize(src.getDisplayOrder())); if (src.getSRS() != null) obj.add("srs", context.serialize(src.getSRS())); if (src.getBackgroundColor() != null) obj.add("backgroundColor", context.serialize(src.getBackgroundColor())); if (src.getServices() != null) obj.add("services", context.serialize(src.getServices())); try {//from w ww . j av a 2s . co m Method method = Theme.class.getMethod("getParameters", (Class<?>[]) null); Type returnType = method.getGenericReturnType(); obj.add("parameters", context.serialize(src.getParameters(), returnType)); } catch (SecurityException e) { logger.error(e.getMessage(), e); } catch (NoSuchMethodException e) { logger.error(e.getMessage(), e); } return obj; }
From source file:com.claresco.tinman.json.JsonUtility.java
License:Open Source License
/** * //from w w w . ja v a 2 s . c o m * Description: * Create a JsonArray from XapiInteractionComponents * * Params: * */ protected static JsonArray jsonArrayFromXapiInteractionComponent( ArrayList<XapiInteractionComponent> theComponents, JsonSerializationContext theContext) { JsonArray theArray = new JsonArray(); for (XapiInteractionComponent component : theComponents) { theArray.add(theContext.serialize(component)); } return theArray; }