Refine search
@Override public JsonElement serialize(OAuth2AccessTokenEntity src, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); o.addProperty("value", src.getValue()); o.addProperty("id", src.getId()); o.addProperty("refreshTokenId", src.getRefreshToken() != null ? src.getRefreshToken().getId() : null); o.add("scopes", context.serialize(src.getScope())); o.addProperty("clientId", src.getClient().getClientId()); o.addProperty("userId", src.getAuthenticationHolder().getAuthentication().getName()); o.add("expiration", context.serialize(src.getExpiration())); return o; }
@Override public JsonElement serialize(Filters src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject result = new JsonObject(); final JsonArray viewFilters = new JsonArray(); for (DashboardFilter f : src.filters()) { viewFilters.add(context.serialize(f, DashboardFilter.class)); } result.add(KEY_FILTERS, viewFilters); return result; } }
@Override public JsonElement serialize(PipelinesDataResponse src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); serialized.add("pipelines", context.serialize(src.getPipelineConfigs(), GROUPS_TYPE)); return serialized; } }
class CollectionAdapter implements JsonSerializer<Collection<?>> { @Override public JsonElement serialize(Collection<?> src, Type typeOfSrc, JsonSerializationContext context) { if (src == null || src.isEmpty()) // exclusion is made here return null; JsonArray array = new JsonArray(); for (Object child : src) { JsonElement element = context.serialize(child); array.add(element); } return array; } }
/** * Serialize the {@link Resources} object if it is not null. */ private void serializeResources(JsonObject jsonObj, String prefix, JsonSerializationContext context, @Nullable Resources resources) { if (resources == null) { return; } String name = prefix + "Resources"; jsonObj.add(name, context.serialize(resources)); }
@Override public JsonElement serialize(DashboardFilter src, Type typeOfSrc, JsonSerializationContext context) { final JsonElement serialized; if (src instanceof WhitelistFilter) { serialized = context.serialize(src, WhitelistFilter.class); serialized.getAsJsonObject().addProperty(KEY_TYPE, TYPE_WHITELIST); } else if (src instanceof BlacklistFilter) { serialized = context.serialize(src, BlacklistFilter.class); serialized.getAsJsonObject().addProperty(KEY_TYPE, TYPE_BLACKLIST); } else { throw new IllegalArgumentException("Don't know how to handle DashboardFilter implementation: " + src.getClass().getCanonicalName()); } serialized.getAsJsonObject().addProperty(KEY_NAME, src.name()); return serialized; } }
public class PropertyBasedInterfaceMarshal implements JsonSerializer<Object>, JsonDeserializer<Object> { private static final String CLASS_META_KEY = "CLASS_META_KEY"; @Override public Object deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { JsonObject jsonObj = jsonElement.getAsJsonObject(); String className = jsonObj.get(CLASS_META_KEY).getAsString(); try { Class<?> clz = Class.forName(className); return jsonDeserializationContext.deserialize(jsonElement, clz); } catch (ClassNotFoundException e) { throw new JsonParseException(e); } } @Override public JsonElement serialize(Object object, Type type, JsonSerializationContext jsonSerializationContext) { JsonElement jsonEle = jsonSerializationContext.serialize(object, object.getClass()); jsonEle.getAsJsonObject().addProperty(CLASS_META_KEY, object.getClass().getCanonicalName()); return jsonEle; } }
@Override public JsonElement serialize(Object src, Type typeOfSrc, JsonSerializationContext context) { if (src.getClass() != Object.class) { return context.serialize(src, src.getClass()); } return new JsonObject(); }
@Override public JsonElement serialize(CRTask crTask, Type type, JsonSerializationContext context) { JsonObject retValue = context.serialize(crTask).getAsJsonObject(); CRTask onCancel = crTask.getOnCancel(); if (onCancel != null) { retValue.remove("onCancel"); retValue.add("onCancel", context.serialize(onCancel)); } return retValue; } }
@Override public JsonElement serialize(CRMaterial material, Type type, JsonSerializationContext context) { return context.serialize(material); } }
@Override public JsonElement serialize(PipelineSelectionResponse src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); JsonArray filters = new JsonArray(); src.filters().filters().forEach((f) -> { filters.add(context.serialize(f, DashboardFilter.class)); }); serialized.add("filters", filters); return serialized; } }
@Override public JsonElement serialize(List<PipelineConfigs> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); for (PipelineConfigs group : src) { final List<PipelineConfig> pipelines = group.getPipelines(); if (!pipelines.isEmpty()) { List<CaseInsensitiveString> pipelineNames = pipelines.stream().map(PipelineConfig::name).collect(Collectors.toList()); serialized.add(group.getGroup(), context.serialize(pipelineNames)); } } return serialized; } }
/** * Serialize the {@link Resources} object if it is not null. */ private void serializeResources(JsonObject jsonObj, String prefix, JsonSerializationContext context, @Nullable Resources resources) { if (resources == null) { return; } String name = prefix + "Resources"; jsonObj.add(name, context.serialize(resources)); }
@Override public JsonElement serialize(Object object, Type type, JsonSerializationContext jsonSerializationContext) { JsonElement jsonEle = jsonSerializationContext.serialize(object, object.getClass()); jsonEle.getAsJsonObject().addProperty("type", object.getClass().getCanonicalName()); return jsonEle; } }
@Override public JsonElement serialize(Object src, Type typeOfSrc, JsonSerializationContext context) { if (src.getClass() != Object.class) { return context.serialize(src, src.getClass()); } return new JsonObject(); }
@Override public JsonElement serialize(CRArtifact crArtifact, Type type, JsonSerializationContext context) { return context.serialize(crArtifact).getAsJsonObject(); } }
@Override public JsonElement serialize(Holder src, Type type, JsonSerializationContext context) { JsonObject root = new JsonObject(); JsonElement value = context.serialize(src.value()); root.addProperty("id", src.id()); if (value.isJsonObject()) { value.getAsJsonObject().addProperty(Holder.TYPE_PROPERTY, src.value().getClass().getName()); } root.add(VALUE_PROPERTY, value); return root; }