com.google.gson.JsonSerializationContext Java Examples
The following examples show how to use
com.google.gson.JsonSerializationContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrincipalCollectionTypeAdapter.java From arcusplatform with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @Override public JsonElement serialize(SimplePrincipalCollection src, Type typeOfSrc, JsonSerializationContext context) { JsonObject response = new JsonObject(); JsonArray principals = new JsonArray(); Set<String> realms = src.getRealmNames(); if (realms != null) { for (String realm : realms) { JsonObject jsonRealm = new JsonObject(); JsonArray realmPrincipals = new JsonArray(); Collection principalCollection = src.fromRealm(realm); if (principalCollection != null && !principalCollection.isEmpty()) { for (Object value : principalCollection) { realmPrincipals.add(context.serialize(value)); } } jsonRealm.add(realm, realmPrincipals); principals.add(jsonRealm); } } response.add(ATTR_PRINCIPAL_MAP, principals); return response; }
Example #2
Source File: JsonCountersIterator.java From datawave with Apache License 2.0 | 6 votes |
@Override public JsonElement serialize(CounterGroup cg, Type t, JsonSerializationContext ctx) { JsonObject obj = new JsonObject(); if (!cg.getName().equals(cg.getDisplayName())) obj.addProperty("displayName", cg.getDisplayName()); JsonObject dns = new JsonObject(); boolean anyNamesDiffer = false; for (Counter c : cg) { obj.addProperty(c.getName(), c.getValue()); if (!c.getName().equals(c.getDisplayName())) anyNamesDiffer = true; dns.addProperty(c.getName(), c.getDisplayName()); } if (anyNamesDiffer) obj.add("displayNames", dns); return obj; }
Example #3
Source File: SourceStateSerialization.java From paintera with GNU General Public License v2.0 | 6 votes |
@Override public JsonObject serialize(final S state, final Type type, final JsonSerializationContext context) { final JsonObject map = new JsonObject(); map.add(COMPOSITE_KEY, context.serialize(state.compositeProperty().get())); map.add(CONVERTER_KEY, context.serialize(state.converter())); map.addProperty(COMPOSITE_TYPE_KEY, state.compositeProperty().get().getClass().getName()); map.addProperty(CONVERTER_TYPE_KEY, state.converter().getClass().getName()); map.add(INTERPOLATION_KEY, context.serialize(state.interpolationProperty().get())); map.addProperty(IS_VISIBLE_KEY, state.isVisibleProperty().get()); map.addProperty(SOURCE_TYPE_KEY, state.getDataSource().getClass().getName()); map.add(SOURCE_KEY, context.serialize(state.getDataSource())); map.addProperty(NAME_KEY, state.nameProperty().get()); map.add(DEPENDS_ON_KEY, context.serialize(getDependencies(state))); return map; }
Example #4
Source File: ReflexDB.java From arcusplatform with Apache License 2.0 | 6 votes |
private static JsonObject convertPc(ReflexActionSendProtocol pr, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("t", "PC"); switch (pr.getType()) { case ZWAVE: json.addProperty("p", "ZW"); break; case ZIGBEE: json.addProperty("p", "ZB"); break; default: throw new RuntimeException("unknown send protocol type: " + pr.getType()); } json.addProperty("m", Base64.encodeBase64String(pr.getMessage())); return json; }
Example #5
Source File: ReflexJson.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public JsonElement serialize(ReflexDriverDefinition driver, Type typeOfSrc, JsonSerializationContext context) { JsonObject drv = new JsonObject(); drv.addProperty("fmt", LATEST.num); drv.addProperty("n", driver.getName()); drv.addProperty("v", driver.getVersion().getRepresentation()); drv.addProperty("h", driver.getHash()); drv.addProperty("o", driver.getOfflineTimeout()); drv.addProperty("m", driver.getMode().name()); drv.add("c", context.serialize(ImmutableList.copyOf(driver.getCapabilities()), LIST_CAPS)); drv.add("r", context.serialize(driver.getReflexes(), LIST_REFLEXES)); if (driver.getDfa() != null) { drv.add("d", context.serialize(driver.getDfa(), REFLEX_DFA)); } return drv; }
Example #6
Source File: ScreenScalesConfigSerializer.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public JsonElement serialize(ScreenScalesConfig screenScalesConfig, Type type, JsonSerializationContext jsonSerializationContext) { LOG.debug("Serializing {}", screenScalesConfig); final JsonObject obj = new JsonObject(); Optional .ofNullable(screenScalesConfig.screenScalesProperty().get()) .map(scales -> scales.getScalesCopy()) .ifPresent(scales -> obj.add(SCALES_KEY, jsonSerializationContext.serialize(scales))); return obj; }
Example #7
Source File: MeshNetworkDeserializer.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns serialized json element containing the allocated group ranges * * @param context Serializer context * @param ranges allocated group range */ private JsonElement serializeAllocatedGroupRanges(@NonNull final JsonSerializationContext context, @NonNull final List<AllocatedGroupRange> ranges) { final Type allocatedGroupRanges = new TypeToken<List<AllocatedGroupRange>>() { }.getType(); return context.serialize(ranges, allocatedGroupRanges); }
Example #8
Source File: ReflexJson.java From arcusplatform with Apache License 2.0 | 5 votes |
private static JsonObject convertAt(ReflexMatchAttribute at, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("t", "AT"); json.addProperty("a", at.getAttr()); json.add("v", context.serialize(at.getValue())); return json; }
Example #9
Source File: GsonHelper.java From steady with Apache License 2.0 | 5 votes |
public JsonElement serialize(ConstructId src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject c = new JsonObject(); c.addProperty("lang", src.getLanguage().toString()); c.addProperty("type", JavaId.typeToString(((JavaId)src).getType())); c.addProperty("qname", src.getQualifiedName()); final Set<String> annotations = ((JavaId)src).getAnnotations(); if(!annotations.isEmpty()) { final JsonArray anno = new JsonArray(); for(String a: annotations) { anno.add(new JsonPrimitive(a)); } c.add("a", anno); } return c; }
Example #10
Source File: ReflexJson.java From arcusplatform with Apache License 2.0 | 5 votes |
private static JsonObject convertAl(ReflexActionAlertmeLifesign al, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("t", "AL"); json.addProperty("a", al.getType().name()); if (al.getMinimum() != null) { json.addProperty("m", al.getMinimum()); } if (al.getNominal() != null) { json.addProperty("n", al.getNominal()); } return json; }
Example #11
Source File: CrosshairConfigSerializer.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public JsonElement serialize(final CrosshairConfig src, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject map = new JsonObject(); map.addProperty(ON_FOCUS_COLOR_KEY, Colors.toHTML(src.getOnFocusColor())); map.addProperty(OFF_FOCUS_COLOR_KEY, Colors.toHTML(src.getOutOfFocusColor())); map.addProperty(VISIBLE_KEY, src.getShowCrosshairs()); return map; }
Example #12
Source File: TimeZoneSerializerAdapter.java From sentry-android with MIT License | 5 votes |
@Override public JsonElement serialize(TimeZone src, Type typeOfSrc, JsonSerializationContext context) { try { return src == null ? null : new JsonPrimitive(src.getID()); } catch (Exception e) { logger.log(SentryLevel.ERROR, "Error when serializing TimeZone", e); } return null; }
Example #13
Source File: SentryIdSerializerAdapter.java From sentry-android with MIT License | 5 votes |
@Override public JsonElement serialize(SentryId src, Type typeOfSrc, JsonSerializationContext context) { try { return src == null ? null : new JsonPrimitive(src.toString()); } catch (Exception e) { logger.log(SentryLevel.ERROR, "Error when serializing SentryId", e); } return null; }
Example #14
Source File: TradeInfoAdapter.java From MeetingFilm with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(List<TradeInfo> tradeInfoList, Type type, JsonSerializationContext jsonSerializationContext) { if (Utils.isListEmpty(tradeInfoList)) { return null; } TradeInfo tradeInfo = tradeInfoList.get(0); if (tradeInfo instanceof PosTradeInfo) { return new JsonPrimitive(StringUtils.join(tradeInfoList, "")); } return jsonSerializationContext.serialize(tradeInfoList); }
Example #15
Source File: BookmarkConfigSerializer.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public JsonElement serialize(BookmarkConfig config, Type typeOfSrc, JsonSerializationContext context) { final JsonObject map = new JsonObject(); final List<BookmarkConfig.Bookmark> bookmarks = new ArrayList<>(config.getUnmodifiableBookmarks()); if (bookmarks.size() > 0) map.add(BOOKMARKS_KEY, context.serialize(bookmarks.toArray())); map.add(TRANSITION_TIME_KEY, context.serialize(config.getTransitionTime())); return map; }
Example #16
Source File: CollectionAdapter.java From symbol-sdk-java with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(Collection<?> src, Type typeOfSrc, JsonSerializationContext context) { if (src == null || src.isEmpty()) { return null; } JsonArray array = new JsonArray(); for (Object child : src) { JsonElement element = context.serialize(child); array.add(element); } return array; }
Example #17
Source File: FieldInsnNodeSerializer.java From maple-ir with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(FieldInsnNode src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = new JsonObject(); jsonObject.add("opcode", context.serialize(src.getOpcode(), Integer.class)); jsonObject.add("owner", context.serialize(src.owner, String.class)); jsonObject.add("name", context.serialize(src.name, String.class)); jsonObject.add("desc", context.serialize(src.desc, String.class)); return jsonObject; }
Example #18
Source File: GetParameterInfoCommandSerializer.java From arcusipcd with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(GetParameterInfoCommand cmd, Type typeOfSrc, JsonSerializationContext context) { final JsonObject object = new JsonObject(); object.add("command", context.serialize(cmd.getCommand())); if (cmd.getTxnid() != null) object.add("txnid", context.serialize(cmd.getTxnid())); return object; }
Example #19
Source File: GetDeviceInfoCommandSerializer.java From arcusipcd with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(GetDeviceInfoCommand cmd, Type typeOfSrc, JsonSerializationContext context) { final JsonObject object = new JsonObject(); object.add("command", context.serialize(cmd.getCommand())); if (cmd.getTxnid() != null) object.add("txnid", context.serialize(cmd.getTxnid())); return object; }
Example #20
Source File: DiscriminatedTypeAdapter.java From icure-backend with GNU General Public License v2.0 | 5 votes |
public JsonElement serialize(T object, Type typeOfSrc, JsonSerializationContext context) { JsonElement el = context.serialize(object, object.getClass()); JsonObject result = el.getAsJsonObject(); String discr = reverseSubclasses.get(object.getClass()); if (discr == null) { throw new JsonParseException("Invalid subclass " + object.getClass()); } result.addProperty(discriminator, discr); return result; }
Example #21
Source File: SetDeviceInfoCommandSerializer.java From arcusipcd with Apache License 2.0 | 5 votes |
public JsonElement serialize(SetDeviceInfoCommand cmd, Type typeOfSrc, JsonSerializationContext context) { final JsonObject object = new JsonObject(); object.add("command", context.serialize(cmd.getCommand())); if (cmd.getTxnid() != null) object.add("txnid", context.serialize(cmd.getTxnid())); if (cmd.getValues() != null) object.add("values", context.serialize(cmd.getValues())); return object; }
Example #22
Source File: GetReportConfigurationCommandSerializer.java From arcusipcd with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(GetReportConfigurationCommand cmd, Type typeOfSrc, JsonSerializationContext context) { final JsonObject object = new JsonObject(); object.add("command", context.serialize(cmd.getCommand())); if (cmd.getTxnid() != null) object.add("txnid", context.serialize(cmd.getTxnid())); return object; }
Example #23
Source File: RebootCommandSerializer.java From arcusipcd with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(RebootCommand cmd, Type typeOfSrc, JsonSerializationContext context) { final JsonObject object = new JsonObject(); object.add("command", context.serialize(cmd.getCommand())); if (cmd.getTxnid() != null) object.add("txnid", context.serialize(cmd.getTxnid())); return object; }
Example #24
Source File: FormulaFactory.java From uyuni with GNU General Public License v2.0 | 5 votes |
@Override public JsonElement serialize(Double src, Type type, JsonSerializationContext context) { if (src % 1 == 0) { return new JsonPrimitive(src.intValue()); } else { return new JsonPrimitive(src); } }
Example #25
Source File: WxMpMassVideoAdapter.java From weixin-java-tools with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(WxMpMassVideo message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); messageJson.addProperty("media_id", message.getMediaId()); messageJson.addProperty("description", message.getDescription()); messageJson.addProperty("title", message.getTitle()); return messageJson; }
Example #26
Source File: operations.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(operation_type src, Type typeOfSrc, JsonSerializationContext context) { JsonArray jsonArray = new JsonArray(); jsonArray.add(src.nOperationType); Type type = operations_map.getOperationObjectById(src.nOperationType); assert(type != null); jsonArray.add(context.serialize(src.operationContent, type)); return jsonArray; }
Example #27
Source File: MultimapSerializer.java From datawave with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(Multimap<String,String> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject mm = new JsonObject(); for (Entry<String,Collection<String>> e : src.asMap().entrySet()) { JsonArray values = new JsonArray(); Collection<String> filtered = Collections2.filter(e.getValue(), Predicates.notNull()); for (String value : filtered) values.add(new JsonPrimitive(value)); mm.add(e.getKey(), values); } return mm; }
Example #28
Source File: WxMpTemplateMessageGsonAdapter.java From weixin-java-tools with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(WxMpTemplateMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); messageJson.addProperty("touser", message.getToUser()); messageJson.addProperty("template_id", message.getTemplateId()); if (message.getUrl() != null) { messageJson.addProperty("url", message.getUrl()); } if (message.getMiniProgram() != null) { JsonObject miniProgramJson = new JsonObject(); miniProgramJson.addProperty("appid", message.getMiniProgram().getAppid()); miniProgramJson.addProperty("pagepath", message.getMiniProgram().getPagePath()); messageJson.add("miniprogram", miniProgramJson); } JsonObject data = new JsonObject(); messageJson.add("data", data); for (WxMpTemplateData datum : message.getData()) { JsonObject dataJson = new JsonObject(); dataJson.addProperty("value", datum.getValue()); if (datum.getColor() != null) { dataJson.addProperty("color", datum.getColor()); } data.add(datum.getName(), dataJson); } return messageJson; }
Example #29
Source File: VarInsnNodeSerializer.java From maple-ir with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(VarInsnNode src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.add("opcode", context.serialize(src.getOpcode())); object.add("var", context.serialize(src.var)); return object; }
Example #30
Source File: FrameNodeSerializer.java From maple-ir with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(FrameNode src, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.add("opcode", context.serialize(src.getOpcode())); object.add("type", context.serialize(src.type)); object.add("local", context.serialize(src.local)); object.add("stack", context.serialize(src.stack)); return object; }