@Override public JsonElement serialize( final Counter src, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject container = new JsonObject(); final JsonObject baseLabels = new JsonObject(); baseLabels.addProperty(Reserved.NAME.label(), src.name); container.add(SERIALIZE_BASE_LABELS, baseLabels); container.addProperty(SERIALIZE_DOCSTRING, src.docstring); final JsonObject metric = new JsonObject(); metric.addProperty("type", "counter"); final JsonArray values = new JsonArray(); for (final Map<String, String> labelSet : src.children.keySet()) { final JsonObject element = new JsonObject(); element.add("labels", context.serialize(labelSet)); final Child vector = src.children.get(labelSet); element.add("value", context.serialize(vector.value.get())); values.add(element); } metric.add("value", values); container.add(SERIALIZE_METRIC, context.serialize(metric)); return container; }
@Override public JsonElement serialize(DataItem src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); if (src.getName() != null) { object.add("name", context.serialize(src.getName())); } if (src.getDoc() != null) { object.addProperty("doc", src.getDoc().getDoc()); } if (src.getType() != null) { object.add("type", context.serialize(src.getType())); } if (src.isOptional()) { object.addProperty("optional", src.isOptional()); if (src.getDefaultValue() != null) { object.add("defaultValue", src.getDefaultValue()); } } return object; }
@Override public JsonElement serialize(RemoteClass src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); if (src.getName() != null) { object.addProperty("name", src.getName()); } if (src.getDoc() != null) { object.addProperty("doc", src.getDoc().getDoc()); } if (src.isAbstract()) { object.add("abstract", new JsonPrimitive(true)); } if (src.getExtends() != null) { object.add("extends", context.serialize(src.getExtends())); } if (!src.getConstructors().isEmpty()) { object.add("constructors", context.serialize(src.getConstructors())); } if (!src.getMethods().isEmpty()) { object.add("methods", context.serialize(src.getMethods())); } if (!src.getEvents().isEmpty()) { object.add("events", context.serialize(src.getEvents())); } return object; }
@Override public JsonElement serialize(Versioning src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); JsonElement type = context.serialize(src.type, VersioningType.class); obj.add("type", type); JsonElement params; switch (src.type) { case EXTERNAL: params = context.serialize(src.params, VersioningExternal.Params.class); break; case SIMPLE: params = context.serialize(src.params, VersioningSimple.Params.class); break; case STAGGERED: params = context.serialize(src.params, VersioningStaggered.Params.class); break; case TRASHCAN: params = context.serialize(src.params, VersioningTrashCan.Params.class); break; case NONE: default: params = null; // context.serialize(src.params, VersioningNone.Params.class); break; } obj.add("params", params); return obj; }
protected void serialize( @Nonnull JsonObject object, @Nonnull BaseComponent component, @Nonnull JsonSerializationContext context) { boolean first = false; if (ComponentSerializer.serializedComponents.get() == null) { first = true; ComponentSerializer.serializedComponents.set(new HashSet<BaseComponent>()); } try { Checks.check( !ComponentSerializer.serializedComponents.get().contains(component), "Component loop"); ComponentSerializer.serializedComponents.get().add(component); if (component.getColorRaw() != null) { object.addProperty("color", component.getColorRaw().getName()); } if (component.isBoldRaw() != null) { object.addProperty("bold", component.isBoldRaw()); } if (component.isItalicRaw() != null) { object.addProperty("italic", component.isItalicRaw()); } if (component.isUnderlinedRaw() != null) { object.addProperty("underlined", component.isUnderlinedRaw()); } if (component.isStrikethroughRaw() != null) { object.addProperty("strikethrough", component.isStrikethroughRaw()); } if (component.isObfuscatedRaw() != null) { object.addProperty("obfuscated", component.isObfuscatedRaw()); } if (component.getExtra() != null) { object.add("extra", context.serialize(component.getExtra())); } // Events if (component.getClickEvent() != null) { JsonObject clickEvent = new JsonObject(); clickEvent.addProperty( "action", component.getClickEvent().getAction().toString().toLowerCase()); clickEvent.addProperty("value", component.getClickEvent().getValue()); object.add("clickEvent", clickEvent); } if (component.getHoverEvent() != null) { JsonObject hoverEvent = new JsonObject(); hoverEvent.addProperty( "action", component.getHoverEvent().getAction().toString().toLowerCase()); hoverEvent.add("value", context.serialize(component.getHoverEvent().getValue())); object.add("hoverEvent", hoverEvent); } } finally { ComponentSerializer.serializedComponents.get().remove(component); if (first) { ComponentSerializer.serializedComponents.set(null); } } }
@Nullable public JsonElement a( ChatModifier chatmodifier, Type type, JsonSerializationContext jsonserializationcontext) { if (chatmodifier.g()) { return null; } else { JsonObject jsonobject = new JsonObject(); if (chatmodifier.c != null) { jsonobject.addProperty("bold", chatmodifier.c); } if (chatmodifier.d != null) { jsonobject.addProperty("italic", chatmodifier.d); } if (chatmodifier.e != null) { jsonobject.addProperty("underlined", chatmodifier.e); } if (chatmodifier.f != null) { jsonobject.addProperty("strikethrough", chatmodifier.f); } if (chatmodifier.g != null) { jsonobject.addProperty("obfuscated", chatmodifier.g); } if (chatmodifier.b != null) { jsonobject.add("color", jsonserializationcontext.serialize(chatmodifier.b)); } if (chatmodifier.j != null) { jsonobject.add("insertion", jsonserializationcontext.serialize(chatmodifier.j)); } JsonObject jsonobject1; if (chatmodifier.h != null) { jsonobject1 = new JsonObject(); jsonobject1.addProperty("action", chatmodifier.h.a().b()); jsonobject1.addProperty("value", chatmodifier.h.b()); jsonobject.add("clickEvent", jsonobject1); } if (chatmodifier.i != null) { jsonobject1 = new JsonObject(); jsonobject1.addProperty("action", chatmodifier.i.a().b()); jsonobject1.add("value", jsonserializationcontext.serialize(chatmodifier.i.b())); jsonobject.add("hoverEvent", jsonobject1); } return jsonobject; } }
@Override public JsonElement serialize( JvmOptions.DebugOptions src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.add("doDebug", context.serialize(src.doDebug())); json.add("doSuspend", context.serialize(src.doSuspend())); if (src.getRunnables() != null) { json.add("runnables", context.serialize(src.getRunnables())); } return json; }
private <T> JsonElement serializeAsElementOrArray( List<T> items, JsonSerializationContext context) { if (items.isEmpty()) { return null; } if (items.size() == 1) { return context.serialize(items.get(0)); } else { return context.serialize(items); } }
public JsonElement a(class_ez var1, Type var2, JsonSerializationContext var3) { if (var1.g()) { return null; } else { JsonObject var4 = new JsonObject(); if (var1.c != null) { var4.addProperty("bold", var1.c); } if (var1.d != null) { var4.addProperty("italic", var1.d); } if (var1.e != null) { var4.addProperty("underlined", var1.e); } if (var1.f != null) { var4.addProperty("strikethrough", var1.f); } if (var1.g != null) { var4.addProperty("obfuscated", var1.g); } if (var1.b != null) { var4.add("color", var3.serialize(var1.b)); } if (var1.j != null) { var4.add("insertion", var3.serialize(var1.j)); } JsonObject var5; if (var1.h != null) { var5 = new JsonObject(); var5.addProperty("action", var1.h.a().b()); var5.addProperty("value", var1.h.b()); var4.add("clickEvent", var5); } if (var1.i != null) { var5 = new JsonObject(); var5.addProperty("action", var1.i.a().b()); var5.add("value", var3.serialize(var1.i.b())); var4.add("hoverEvent", var5); } return var4; } }
private JsonElement serializeModule( ProjectConfig moduleConfig, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("name", moduleConfig.getName()); object.addProperty("path", moduleConfig.getPath()); object.addProperty("type", moduleConfig.getType()); object.addProperty("content_root", moduleConfig.getContentRoot()); object.add("attributes", context.serialize(moduleConfig.getAttributes())); object.add("modules", serializeModules(moduleConfig, context)); object.add("source", context.serialize(moduleConfig.getSource())); return object; }
@Override public JsonElement serialize( FirewallOptions src, Type typeOfSrc, JsonSerializationContext context) { JsonObject firewall = new JsonObject(); if (src.getName() != null) { firewall.addProperty("name", src.getName()); } if (src.getNetwork() != null) { firewall.addProperty("network", src.getNetwork().toString()); } if (!src.getSourceRanges().isEmpty()) { firewall.add("sourceRanges", buildArrayOfStrings(src.getSourceRanges())); } if (!src.getSourceTags().isEmpty()) { firewall.add("sourceTags", buildArrayOfStrings(src.getSourceTags())); } if (!src.getTargetTags().isEmpty()) { firewall.add("targetTags", buildArrayOfStrings(src.getTargetTags())); } if (!src.getAllowed().isEmpty()) { JsonArray rules = new JsonArray(); for (Rule rule : src.getAllowed()) { rules.add(context.serialize(rule, Firewall.Rule.class)); } firewall.add("allowed", rules); } return firewall; }
@Override public JsonElement serialize( AssignedLabel<T> tAssignedLabel, Type type, JsonSerializationContext jsonSerializationContext) { return jsonSerializationContext.serialize(new ShallowAssign<T>(tAssignedLabel)); }
@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; }
@Override public JsonElement serialize(MoveStrategy src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getSimpleName())); result.add("properties", context.serialize(src, src.getClass())); return result; }
@Override public JsonElement serialize( PartitionMethodDescExpr src, Type typeOfSrc, JsonSerializationContext context) { switch (src.getPartitionType()) { case RANGE: return context.serialize(src, RangePartition.class); case HASH: return context.serialize(src, HashPartition.class); case LIST: return context.serialize(src, ListPartition.class); case COLUMN: return context.serialize(src, ColumnPartition.class); default: return null; } }
private void serializeBlock( SegmentBlock segment, JsonObject json, JsonSerializationContext context) { json.add("actions", serializeAsElementOrArray(segment.types, context)); json.addProperty("meta", segment.getMeta()); if (segment.clientUpdate != null) { JsonObject jsonUpdate = new JsonObject(); jsonUpdate.add("coords", context.serialize(segment.clientUpdate.relativeCoords)); json.add("clientUpdate", jsonUpdate); } }
public JsonObject serialize(AbstractBill src, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.addProperty("id", src.getId()); result.addProperty("code", src.getCode()); result.add("billDate", context.serialize(src.getBillDate())); result.add("dateFrom", context.serialize(src.getDateFrom())); result.add("dateTo", context.serialize(src.getDateTo())); result.add("amount", context.serialize(src.getAmount())); result.addProperty("comments", src.getComments()); result.addProperty("commentsPdf", src.getCommentsPdf()); if (src.getSender() != null) { JsonObject sender = new JsonObject(); sender.addProperty("id", src.getSender().getId()); sender.addProperty("name", src.getSender().getName()); result.add("sender", sender); } if (src.getReceiver() != null) { JsonObject receiver = new JsonObject(); receiver.addProperty("id", src.getReceiver().getId()); receiver.addProperty("name", src.getReceiver().getName()); result.add("receiver", receiver); } if (src.getModel() != null) { JsonObject model = new JsonObject(); model.addProperty("id", src.getModel().getId()); model.addProperty("name", src.getModel().getName()); result.add("model", model); } if (src.getCurrentState() != null) { result.add("currentState", context.serialize(src.getCurrentState())); } if (src.getPdfFile() != null) { result.add("pdfFile", context.serialize(src.getPdfFile())); } if (src.getAuditData() != null) { result.add("auditData", context.serialize(src.getAuditData())); } return result; }
@Override public JsonElement serialize( AssetReference asset, Type typeOfSrc, JsonSerializationContext context) { JsonElement jsonAsset = context.serialize(asset.asset, asset.asset.getClass()); GsonUtils.appendClassProperty(jsonAsset, asset.asset, context); JsonObject jsonObject = new JsonObject(); jsonObject.add("asset", jsonAsset); return jsonObject; }
private void serializeItem( SegmentItem segment, JsonObject json, JsonSerializationContext context) { json.add("actions", serializeAsElementOrArray(segment.types, context)); json.addProperty("isAdjacent", segment.isAdjacent); if (segment.clientUpdate != null) { JsonObject jsonUpdate = new JsonObject(); jsonUpdate.add("coords", context.serialize(segment.clientUpdate.relativeCoords)); jsonUpdate.addProperty("directional", segment.directionalClientUpdate); json.add("clientUpdate", jsonUpdate); } }
@Override public JsonElement serialize( Data<T> data, Type type, JsonSerializationContext jsonSerializationContext) { Set<String> workers = new HashSet<String>(); for (Worker<T> worker : data.getWorkers()) { workers.add(worker.getName()); } JsonElement jworkers = jsonSerializationContext.serialize(workers); JsonElement objects = jsonSerializationContext.serialize(data.getObjects()); JsonElement goldObjects = jsonSerializationContext.serialize(data.getGoldObjects()); JsonElement evaluationObjects = jsonSerializationContext.serialize(data.getEvaluationObjects()); JsonElement assigns = jsonSerializationContext.serialize(data.getAssigns()); JsonObject je = new JsonObject(); je.add("workers", jworkers); je.add("objects", objects); je.add("goldObjects", goldObjects); je.add("evaluationObjects", evaluationObjects); je.add("assigns", assigns); return je; }
private void serializeChatStyle( ChatStyle style, JsonObject object, JsonSerializationContext ctx) { JsonElement jsonelement = ctx.serialize(style); if (jsonelement.isJsonObject()) { JsonObject jsonobject1 = (JsonObject) jsonelement; Iterator iterator = jsonobject1.entrySet().iterator(); while (iterator.hasNext()) { Entry entry = (Entry) iterator.next(); object.add((String) entry.getKey(), (JsonElement) entry.getValue()); } } }
private void serializeChatStyle( ChatStyle style, JsonObject object, JsonSerializationContext ctx) { JsonElement var4 = ctx.serialize(style); if (var4.isJsonObject()) { JsonObject var5 = (JsonObject) var4; Iterator var6 = var5.entrySet().iterator(); while (var6.hasNext()) { Entry var7 = (Entry) var6.next(); object.add((String) var7.getKey(), (JsonElement) var7.getValue()); } } }
@Override public JsonElement serialize( InstanceTemplate src, Type typeOfSrc, JsonSerializationContext context) { InstanceTemplateInternal template = new InstanceTemplateInternal(src); JsonObject instance = (JsonObject) context.serialize(template, InstanceTemplateInternal.class); // deal with network JsonArray networkInterfaces = new JsonArray(); for (InstanceTemplate.NetworkInterface networkInterface : template.getNetworkInterfaces()) { networkInterfaces.add( context.serialize(networkInterface, InstanceTemplate.NetworkInterface.class)); } instance.add("networkInterfaces", networkInterfaces); // deal with persistent disks if (src.getDisks() != null && !src.getDisks().isEmpty()) { JsonArray disks = new JsonArray(); for (InstanceTemplate.PersistentDisk persistentDisk : src.getDisks()) { JsonObject disk = (JsonObject) context.serialize(persistentDisk, InstanceTemplate.PersistentDisk.class); disk.addProperty("type", "PERSISTENT"); disks.add(disk); } instance.add("disks", disks); } // deal with metadata if (src.getMetadata() != null && !src.getMetadata().isEmpty()) { JsonObject metadata = (JsonObject) context.serialize(new Metadata(src.getMetadata())); instance.add("metadata", metadata); return instance; } return instance; }
@Override public JsonElement serialize(JsonRpcResponse src, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.addProperty(ResponseProperty.ID.key(), src.getId()); if (src.isError()) { JsonObject error = new JsonObject(); error.addProperty(ParamsProperty.MESSAGE.key(), src.getErrorMessage()); result.add(ResponseProperty.ERROR.key(), error); } else { JsonObject data = new JsonObject(); for (Entry<ParamsProperty, Object> properties : src.getData().entrySet()) { data.add(properties.getKey().key(), context.serialize(properties.getValue())); } result.add(ResponseProperty.DATA.key(), data); } return result; }
@Override public JsonElement serialize( BindsConfig src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); SetMultimap<Name, SimpleUri> bindByModule = HashMultimap.create(); for (SimpleUri key : src.data.keySet()) { bindByModule.put(key.getModuleName(), key); } List<Name> sortedModules = Lists.newArrayList(bindByModule.keySet()); Collections.sort(sortedModules); for (Name moduleId : sortedModules) { SetMultimap<String, Input> moduleBinds = HashMultimap.create(); for (SimpleUri bindUri : bindByModule.get(moduleId)) { moduleBinds.putAll(bindUri.getObjectName().toString(), src.data.get(bindUri)); } JsonElement map = context.serialize(moduleBinds, SetMultimap.class); result.add(moduleId.toString(), map); } return result; }
@Override public JsonElement serialize( Segment segment, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("class", segment.checkClass.getName()); if (segment instanceof SegmentSpecialBlock) { json.addProperty("type", "specialBlock"); serializeSpecialBlock((SegmentSpecialBlock) segment, json, context); } else { if (segment instanceof SegmentBlock) { json.addProperty("type", "block"); serializeBlock((SegmentBlock) segment, json, context); } else if (segment instanceof SegmentEntity) { json.addProperty("type", "entity"); serializeEntity((SegmentEntity) segment, json, context); } else if (segment instanceof SegmentItem) { json.addProperty("type", "item"); serializeItem((SegmentItem) segment, json, context); } else if (segment instanceof SegmentTileEntity) { json.addProperty("type", "tileEntity"); serializeTileEntity((SegmentTileEntity) segment, json, context); } json.add("flags", serializeAsElementOrArray(segment.flags, context)); if (segment.condition != null) { json.addProperty("condition", segment.condition.toString()); } if (segment.priority != Priority.NORMAL) { json.addProperty("priority", segment.priority.toString()); } for (Getter getter : segment.getters) { json.add(getter.getName(), context.serialize(getter, Getter.class)); } } return json; }
/** @see JsonSerializer#serialize(Object, Type, JsonSerializationContext) */ @Override public JsonElement serialize( org.redpin.base.core.Fingerprint src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src, Fingerprint.class); }
@Override public JsonElement serialize( WorkflowTokenDetail src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getTokenData()); }
@Override public JsonElement serialize( HostResourceUsage hostResourceUsage, Type type, JsonSerializationContext context) { return context.serialize(hostResourceUsage); }
/** * This allows for the serialization of objects that use an interface to be wrapped and retain * memory of its type. * * @return Returns the JsonElement to be used by Gson */ public JsonElement serialize(T object, Type interfaceType, JsonSerializationContext context) { final JsonObject wrapper = new JsonObject(); wrapper.addProperty("type", object.getClass().getName()); wrapper.add("data", context.serialize(object)); return wrapper; }