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 Project: arcusplatform Author: arcus-smart-home File: PrincipalCollectionTypeAdapter.java License: 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 Project: datawave Author: NationalSecurityAgency File: JsonCountersIterator.java License: 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 Project: paintera Author: saalfeldlab File: SourceStateSerialization.java License: 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 Project: arcusplatform Author: arcus-smart-home File: ReflexDB.java License: 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 Project: arcusplatform Author: arcus-smart-home File: ReflexJson.java License: 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 Project: paintera Author: saalfeldlab File: ScreenScalesConfigSerializer.java License: 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 Project: Android-nRF-Mesh-Library Author: NordicSemiconductor File: MeshNetworkDeserializer.java License: 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 Project: arcusplatform Author: arcus-smart-home File: ReflexJson.java License: 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 Project: steady Author: eclipse File: GsonHelper.java License: 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 Project: arcusplatform Author: arcus-smart-home File: ReflexJson.java License: 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 Project: paintera Author: saalfeldlab File: CrosshairConfigSerializer.java License: 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 Project: sentry-android Author: getsentry File: TimeZoneSerializerAdapter.java License: 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 Project: sentry-android Author: getsentry File: SentryIdSerializerAdapter.java License: 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 Project: MeetingFilm Author: daydreamdev File: TradeInfoAdapter.java License: 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 Project: paintera Author: saalfeldlab File: BookmarkConfigSerializer.java License: 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 Project: symbol-sdk-java Author: nemtech File: CollectionAdapter.java License: 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 Project: maple-ir Author: LLVM-but-worse File: FieldInsnNodeSerializer.java License: 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 Project: arcusipcd Author: arcus-smart-home File: GetParameterInfoCommandSerializer.java License: 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 Project: arcusipcd Author: arcus-smart-home File: GetDeviceInfoCommandSerializer.java License: 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 Project: icure-backend Author: taktik File: DiscriminatedTypeAdapter.java License: 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 Project: arcusipcd Author: arcus-smart-home File: SetDeviceInfoCommandSerializer.java License: 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 Project: arcusipcd Author: arcus-smart-home File: GetReportConfigurationCommandSerializer.java License: 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 Project: arcusipcd Author: arcus-smart-home File: RebootCommandSerializer.java License: 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 Project: uyuni Author: uyuni-project File: FormulaFactory.java License: 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 Project: weixin-java-tools Author: DarLiner File: WxMpMassVideoAdapter.java License: 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 Project: guarda-android-wallets Author: guardaco File: operations.java License: 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 Project: datawave Author: NationalSecurityAgency File: MultimapSerializer.java License: 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 Project: weixin-java-tools Author: DarLiner File: WxMpTemplateMessageGsonAdapter.java License: 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 Project: maple-ir Author: LLVM-but-worse File: VarInsnNodeSerializer.java License: 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 Project: maple-ir Author: LLVM-but-worse File: FrameNodeSerializer.java License: 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; }