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:org.eclipse.che.api.workspace.server.stack.adapters.StackComponentAdapter.java

License:Open Source License

@Override
public JsonElement serialize(StackComponent src, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(src, StackComponentImpl.class);
}

From source file:org.eclipse.che.api.workspace.server.stack.adapters.StackSourceAdapter.java

License:Open Source License

@Override
public JsonElement serialize(StackSource target, Type type, JsonSerializationContext context) {
    return context.serialize(target, StackSourceImpl.class);
}

From source file:org.eclipse.che.api.workspace.server.stack.adapters.WorkspaceConfigAdapter.java

License:Open Source License

@Override
public JsonElement serialize(WorkspaceConfig src, Type typeOfSrc, JsonSerializationContext context) {
    return context.serialize(src, WorkspaceConfigImpl.class);
}

From source file:org.eclipse.packagedrone.repo.channel.impl.DeployGroupTypeAdapter.java

License:Open Source License

@Override
public JsonElement serialize(final DeployGroup group, final Type type, final JsonSerializationContext ctx) {
    final JsonObject obj = new JsonObject();

    obj.addProperty("id", group.getId());
    obj.addProperty("name", group.getName());

    final JsonObject keys = new JsonObject();
    obj.add("keys", keys);

    for (final DeployKey key : group.getKeys()) {
        final JsonObject ok = new JsonObject();
        ok.addProperty("name", key.getName());
        ok.addProperty("key", key.getKey());
        ok.add("timestamp", ctx.serialize(Date.from(key.getCreationTimestamp()), Date.class));
        keys.add(key.getId(), ok);//from w ww  .j ava  2 s  .c  o  m
    }

    return obj;
}

From source file:org.jboss.rhq.sync.tool.actions.impl.impex.RoleSerializer.java

License:Open Source License

@Override
public JsonElement serialize(Role role, Type type, JsonSerializationContext ctx) {
    if (logger.isDebugEnabled())
        LogUtils.logRoleInstance(logger, role, "Serializing...");
    JsonObject result = new JsonObject();
    result.add("id", ctx.serialize(role.getId(), Integer.class));
    result.add("name", ctx.serialize(role.getName(), String.class));
    result.add("classname", ctx.serialize(role.getClass().toString(), String.class));
    result.add("description", ctx.serialize(role.getDescription(), String.class));
    result.add("fsystem", ctx.serialize(role.getFsystem(), Boolean.class));
    result.add("memberCount", ctx.serialize(role.getMemberCount(), Integer.class));
    result.add("permission", ctx.serialize(role.getPermissions(), Collection.class));
    result.add("subjects", ctx.serialize(role.getSubjects(), Collection.class));
    return result;
}

From source file:org.jboss.rhq.sync.tool.actions.impl.impex.SubjectSerializer.java

License:Open Source License

@Override
public JsonElement serialize(Subject subject, Type type, JsonSerializationContext ctx) {
    JsonObject result = new JsonObject();
    result.add("id", ctx.serialize(subject.getId(), Integer.class));
    result.add("name", ctx.serialize(subject.getName(), String.class));
    result.add("classname", ctx.serialize(subject.getClass().toString(), String.class));
    result.add("firstName", ctx.serialize(subject.getFirstName(), String.class));
    result.add("lastName", ctx.serialize(subject.getLastName(), String.class));
    result.add("emailAddress", ctx.serialize(subject.getEmailAddress(), String.class));
    result.add("department", ctx.serialize(subject.getDepartment(), String.class));
    result.add("phoneNumber", ctx.serialize(subject.getPhoneNumber(), String.class));
    result.add("smsAddress", ctx.serialize(subject.getSmsAddress(), String.class));
    result.add("fsystem", ctx.serialize(subject.getFsystem(), Boolean.class));
    result.add("factive", ctx.serialize(subject.getFactive(), Boolean.class));
    result.add("ownedGroups", ctx.serialize(groups(subject.getOwnedGroups()), Set.class));
    result.add("ldapRoles", ctx.serialize(subject.getLdapRoles(), Set.class)); //No support for LDAP Roles
    return result;
}

From source file:org.jboss.rhq.sync.tool.model.impex.serialization.BasicPropertyTypeSerializeAdapter.java

License:Open Source License

@Override
public JsonElement serialize(BasicProperty property, Type type,
        JsonSerializationContext jsonSerializationContext) {
    JsonObject result = new JsonObject();
    result.add("key", jsonSerializationContext.serialize(property.getKey(), String.class));
    if (property instanceof MapProperty) {
        result.add("propertyMap",
                jsonSerializationContext.serialize(((MapProperty) property).getPropertyMap(), Map.class));
    } else if (property instanceof ListProperty) {
        result.add("propertyList",
                jsonSerializationContext.serialize(((ListProperty) property).getPropertyList(), List.class));
    } else {/*from w  w w.  j av  a 2 s.  c om*/
        result.add("value", jsonSerializationContext.serialize(property.getValue(), String.class));
    }
    return result;
}

From source file:org.jboss.rhq.sync.tool.model.impex.serialization.PropertySimpleDeserializer.java

License:Open Source License

@Override
public JsonElement serialize(PropertySimple property, Type type,
        JsonSerializationContext jsonSerializationContext) {
    logger.debug("Serializing instance of " + PropertySimple.class + ":[" + property.toString() + "]");
    JsonObject result = new JsonObject();
    result.add(property.getName(), jsonSerializationContext.serialize(property.getStringValue(), String.class));
    return result;
}

From source file:org.kie.workbench.common.forms.serialization.impl.FieldSerializer.java

License:Apache License

@Override
public JsonElement serialize(FieldDefinition field, Type type, JsonSerializationContext context) {
    JsonElement serializedField = context.serialize(field, field.getClass());

    serializedField.getAsJsonObject().addProperty("code", field.getFieldType().getTypeName());
    serializedField.getAsJsonObject().addProperty("serializedFieldClassName", field.getClass().getName());

    return serializedField;
}

From source file:org.kie.workbench.common.forms.serialization.impl.FormModelSerializer.java

License:Apache License

@Override
public JsonElement serialize(FormModel formModel, Type type, JsonSerializationContext context) {
    JsonElement serializedModel = context.serialize(formModel, formModel.getClass());

    serializedModel.getAsJsonObject().addProperty("formModelType", formModel.getClass().getName());

    return serializedModel;
}