List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:com.vmware.dcp.common.serialization.ObjectMapTypeConverter.java
License:Open Source License
@Override public JsonElement serialize(Map<String, Object> map, Type type, JsonSerializationContext context) { JsonObject mapObject = new JsonObject(); for (Entry<String, Object> e : map.entrySet()) { Object v = e.getValue();//from w w w . j a v a 2 s. co m if (v instanceof JsonObject) { mapObject.add(e.getKey(), (JsonObject) v); } else if (v instanceof String) { mapObject.add(e.getKey(), new JsonParser().parse((String) v)); } else { mapObject.add(e.getKey(), context.serialize(v)); } } return mapObject; }
From source file:com.vmware.xenon.common.serialization.ObjectCollectionTypeConverter.java
License:Open Source License
@Override public JsonElement serialize(Collection<Object> set, Type type, JsonSerializationContext context) { JsonArray setObject = new JsonArray(); for (Object e : set) { if (e == null) { setObject.add(JsonNull.INSTANCE); } else if (e instanceof JsonElement) { setObject.add((JsonElement) e); } else {// w w w. j a va 2 s . co m setObject.add(context.serialize(e)); } } return setObject; }
From source file:com.xse.optstack.persconftool.base.persistence.DefaultDataApplicationTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(final EApplication src, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject obj = new JsonObject(); switch (src.getGroup().getType()) { case APPLICATION: obj.add(PersConfDefinitions.CONFIG_APPL_KEY_NAME, context.serialize(src.getName())); break;//from w ww . j a va 2 s. co m case PUBLIC: obj.add(PersConfDefinitions.CONFIG_DEFAULT_PUBLIC_KEY, context.serialize(PersConfDefinitions.CONFIG_DEFAULT_PUBLIC_VALUE)); break; case SHARED: obj.add(PersConfDefinitions.CONFIG_DEFAULT_GROUP_KEY_PREFIX + src.getName(), context.serialize(PersConfDefinitions.CONFIG_DEFAULT_GROUP_VALUE_PREFIX + src.getName())); break; default: Logger.warn(Activator.PLUGIN_ID, "Invalid application group type: " + src.getGroup().getType()); break; } obj.add(PersConfDefinitions.VERSION_KEY_NAME, context.serialize(src.getVersion())); final Map<String, JsonElement> map = new HashMap<>(); for (final EResource eResource : src.getResources()) { final EDefaultData defaultData = this.isFactory ? eResource.getConfiguration().getFactoryDefault() : eResource.getConfiguration().getConfigDefault(); if (hasDefaultDataValue(defaultData)) { map.put(eResource.getName(), context.serialize(defaultData)); } } obj.add(PersConfDefinitions.RESOURCES_KEY_NAME, context.serialize(map)); return obj; }
From source file:com.xse.optstack.persconftool.base.persistence.ResouceConfigurationApplicationTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(final EApplication src, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject obj = new JsonObject(); if (src.getGroup().getType() == EGroupType.APPLICATION) { obj.add(PersConfDefinitions.CONFIG_APPL_KEY_NAME, context.serialize(src.getName())); } else {// w w w . j a va 2s .c o m obj.add(PersConfDefinitions.CONFIG_APPL_KEY_NAME, context.serialize(PersConfDefinitions.CONFIG_SHARED_VALUE)); } obj.add(PersConfDefinitions.VERSION_KEY_NAME, context.serialize(src.getVersion())); final Map<String, JsonElement> map = new HashMap<>(); src.getResources() .forEach(resource -> map.put(resource.getName(), context.serialize(resource.getConfiguration()))); obj.add(PersConfDefinitions.RESOURCES_KEY_NAME, context.serialize(map)); return obj; }
From source file:com.xse.optstack.persconftool.base.persistence.ResourceConfigurationConfigurationTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(final EConfiguration src, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject obj = new JsonObject(); obj.add(PersconfPackage.Literals.ECONFIGURATION__POLICY.getName(), context.serialize(src.getPolicy())); obj.add(PersconfPackage.Literals.ECONFIGURATION__PERMISSION.getName(), context.serialize(src.getPermission())); obj.add(PersconfPackage.Literals.ECONFIGURATION__STORAGE.getName(), context.serialize(src.getStorage())); if (!StringUtils.isEmpty(src.getMax_size())) { obj.add(PersconfPackage.Literals.ECONFIGURATION__MAX_SIZE.getName(), context.serialize(src.getMax_size())); } else {/*from w ww .j a v a2 s . com*/ obj.add(PersconfPackage.Literals.ECONFIGURATION__MAX_SIZE.getName(), context.serialize(PersConfDefinitions.NA_NAME)); } if (!StringUtils.isEmpty(src.getResponsible())) { obj.add(PersconfPackage.Literals.ECONFIGURATION__RESPONSIBLE.getName(), context.serialize(src.getResponsible())); } else { obj.add(PersconfPackage.Literals.ECONFIGURATION__RESPONSIBLE.getName(), context.serialize(PersConfDefinitions.NA_NAME)); } if (!StringUtils.isEmpty(src.getCustom_name())) { obj.add(PersconfPackage.Literals.ECONFIGURATION__CUSTOM_NAME.getName(), context.serialize(src.getCustom_name())); } else { obj.add(PersconfPackage.Literals.ECONFIGURATION__CUSTOM_NAME.getName(), context.serialize(PersConfDefinitions.NA_NAME)); } if (src.getType() != EDefaultDataType.NA) { obj.add(PersconfPackage.Literals.ECONFIGURATION__TYPE.getName(), context.serialize(src.getType())); } if (!StringUtils.isEmpty(src.getCustomID())) { obj.add(PersconfPackage.Literals.ECONFIGURATION__CUSTOM_ID.getName(), context.serialize(src.getCustomID())); } else { obj.add(PersconfPackage.Literals.ECONFIGURATION__CUSTOM_ID.getName(), context.serialize(PersConfDefinitions.NA_NAME)); } return obj; }
From source file:com.yandex.money.api.typeadapters.model.showcase.container.GroupTypeAdapter.java
License:Open Source License
@Override protected JsonElement serializeItem(Component src, JsonSerializationContext context) { return context.serialize(src); }
From source file:com.yandex.money.api.typeadapters.model.showcase.FeeTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(Fee src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src); }
From source file:de.bwravencl.controllerbuddy.json.ActionTypeAdapter.java
License:Open Source License
@Override public JsonElement serialize(final IAction<?> src, final Type typeOfSrc, final JsonSerializationContext context) { final var wrapper = new JsonObject(); wrapper.addProperty(PROPERTY_TYPE, src.getClass().getName()); wrapper.add(PROPERTY_DATA, context.serialize(src)); return wrapper; }
From source file:de.dentrassi.pm.maven.NodeAdapter.java
License:Open Source License
@Override public JsonElement serialize(final Node node, final Type type, final JsonSerializationContext ctx) { if (node == null) { return JsonNull.INSTANCE; }//from ww w.jav a 2s.co m final JsonObject o = new JsonObject(); if (node instanceof ContentNode && !(node instanceof DataNode)) { final ContentNode cnode = (ContentNode) node; o.addProperty("type", DataNode.class.getSimpleName()); o.add("node", ctx.serialize(new DataNode(cnode.getData(), cnode.getMimeType()))); } else { o.addProperty("type", node.getClass().getSimpleName()); o.add("node", ctx.serialize(node)); } return o; }
From source file:de.justi.yagw2api.common.json.TupleTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(final Tuple src, final Type typeOfSrc, final JsonSerializationContext context) { final JsonArray jsonArray = new JsonArray(); for (Object tuplePart : src.asList()) { jsonArray.add(context.serialize(tuplePart)); }/* w ww. j a v a 2 s .c o m*/ return jsonArray; }