Example usage for com.google.gson JsonSerializationContext serialize

List of usage examples for com.google.gson JsonSerializationContext serialize

Introduction

In this page you can find the example usage for com.google.gson JsonSerializationContext serialize.

Prototype

public JsonElement serialize(Object src, Type typeOfSrc);

Source Link

Document

Invokes default serialization on the specified object passing the specific type information.

Usage

From source file:co.cask.cdap.internal.app.ProcedureSpecificationCodec.java

License:Apache License

@Override
public JsonElement serialize(ProcedureSpecification 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("datasets", serializeSet(src.getDataSets(), context, String.class));
    jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
    jsonObj.add("resources", context.serialize(src.getResources(), new TypeToken<ResourceSpecification>() {
    }.getType()));/*w  ww .java2s  . co m*/
    jsonObj.addProperty("instances", src.getInstances());
    return jsonObj;
}

From source file:co.cask.cdap.internal.app.runtime.codec.ArgumentsCodec.java

License:Apache License

@Override
public JsonElement serialize(Arguments src, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(src.asMap(), MAP_STRING_STRING_TYPE);
}

From source file:co.cask.cdap.internal.app.runtime.codec.ProgramOptionsCodec.java

License:Apache License

@Override
public JsonElement serialize(ProgramOptions src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject json = new JsonObject();
    json.addProperty("name", src.getName());
    json.add("arguments", context.serialize(src.getArguments(), Arguments.class));
    json.add("userArguments", context.serialize(src.getUserArguments(), Arguments.class));
    json.addProperty("debug", src.isDebug());

    return json;/*from w  w w.  j  ava  2  s. c o m*/
}

From source file:co.cask.cdap.internal.app.ServiceSpecificationCodec.java

License:Apache License

@Override
public JsonElement serialize(ServiceSpecification spec, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject object = new JsonObject();
    object.addProperty("className", spec.getClassName());
    object.addProperty("name", spec.getName());
    object.addProperty("description", spec.getDescription());
    object.add("handlers", serializeMap(spec.getHandlers(), context, HttpServiceHandlerSpecification.class));
    object.add("resources", context.serialize(spec.getResources(), Resources.class));
    object.addProperty("instances", spec.getInstances());
    return object;
}

From source file:co.cask.cdap.proto.codec.BasicThrowableCodec.java

License:Apache License

@Override
public JsonElement serialize(BasicThrowable src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject json = new JsonObject();
    json.addProperty("className", src.getClassName());
    json.addProperty("message", src.getMessage());
    json.add("stackTraces", context.serialize(src.getStackTraces(), StackTraceElement[].class));
    json.add("cause", context.serialize(src.getCause(), BasicThrowable.class));
    return json;/*from  w  w  w .  j av a  2s.c  o m*/
}

From source file:co.cask.cdap.proto.codec.FlowletSpecificationCodec.java

License:Apache License

@Override
public JsonElement serialize(FlowletSpecification 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("failurePolicy", new JsonPrimitive(src.getFailurePolicy().name()));
    jsonObj.add("datasets", serializeSet(src.getDataSets(), context, String.class));
    jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
    jsonObj.add("resources", context.serialize(src.getResources(), Resources.class));

    return jsonObj;
}

From source file:co.cask.cdap.proto.codec.ScheduleSpecificationCodec.java

License:Apache License

@SuppressWarnings("deprecation")
@Override/*w  ww .j  a  v  a2  s . c om*/
public JsonElement serialize(ScheduleSpecification src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject jsonObj = new JsonObject();

    ScheduleType scheduleType = ScheduleType.fromSchedule(src.getSchedule());
    if (scheduleType.equals(ScheduleType.TIME)) {
        jsonObj.add("scheduleType", context.serialize(ScheduleType.TIME, ScheduleType.class));
        jsonObj.add("schedule", context.serialize(src.getSchedule(), TimeSchedule.class));
    } else if (scheduleType.equals(ScheduleType.STREAM)) {
        jsonObj.add("scheduleType", context.serialize(ScheduleType.STREAM, ScheduleType.class));
        jsonObj.add("schedule", context.serialize(src.getSchedule(), StreamSizeSchedule.class));
    }

    jsonObj.add("program", context.serialize(src.getProgram(), ScheduleProgramInfo.class));
    jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
    return jsonObj;
}

From source file:co.cask.cdap.proto.codec.WorkerSpecificationCodec.java

License:Apache License

@Override
public JsonElement serialize(WorkerSpecification spec, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject object = new JsonObject();
    object.addProperty("className", spec.getClassName());
    object.addProperty("name", spec.getName());
    object.addProperty("description", spec.getDescription());
    object.add("properties", serializeMap(spec.getProperties(), context, String.class));
    object.add("resources", context.serialize(spec.getResources(), Resources.class));
    object.add("datasets", serializeSet(spec.getDatasets(), context, String.class));
    object.addProperty("instances", spec.getInstances());
    return object;
}

From source file:co.cask.cdap.proto.codec.WorkflowNodeThrowableCodec.java

License:Apache License

@Override
public JsonElement serialize(WorkflowNodeThrowable src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject json = new JsonObject();
    json.addProperty("className", src.getClassName());
    json.addProperty("message", src.getMessage());
    json.add("stackTraces", context.serialize(src.getStackTraces(), StackTraceElement[].class));
    json.add("cause", context.serialize(src.getCause(), WorkflowNodeThrowable.class));
    return json;/*w ww  .java 2 s  .  c  om*/
}

From source file:co.cask.tigon.internal.app.FlowletSpecificationCodec.java

License:Apache License

@Override
public JsonElement serialize(FlowletSpecification 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("failurePolicy", new JsonPrimitive(src.getFailurePolicy().name()));
    jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class));
    jsonObj.add("resources", context.serialize(src.getResources(), new TypeToken<ResourceSpecification>() {
    }.getType()));/*from   w  ww .ja va 2s. c  o m*/
    jsonObj.add("maxInstances", new JsonPrimitive(src.getMaxInstances()));

    return jsonObj;
}