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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: ResultTypeAdapter.java From arcusplatform with Apache License 2.0 | 5 votes |
private JsonElement serializeValue(JsonSerializationContext context, Object value) { if(value == null) { return null; } JsonObject object = new JsonObject(); object.add(ATTR_VALUE_TYPE, context.serialize(value.getClass().getName())); object.add(ATTR_VALUE, context.serialize(value, value.getClass())); return object; }
Example #7
Source File: ScaleBarOverlayConfigSerializer.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public JsonElement serialize( final ScaleBarOverlayConfig config, final Type typeOfSrc, final JsonSerializationContext context) { final JsonObject map = new JsonObject(); map.add(OVERLAY_FONT_KEY, context.serialize(config.getOverlayFont())); map.addProperty(FOREGROUND_COLOR_KEY, Colors.toHTML(config.getForegroundColor())); map.addProperty(BACKGROUND_COLOR_KEY, Colors.toHTML(config.getBackgroundColor())); map.addProperty(IS_SHOWING_KEY, config.getIsShowing()); map.addProperty(TARGET_SCALE_BAR_LENGTH, config.getTargetScaleBarLength()); return map; }
Example #8
Source File: ReflexDB.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(ReflexDefinition src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.add("m", convertMatches(src.getMatchers(), context)); json.add("a", convertActions(src.getActions(), context)); return json; }
Example #9
Source File: JsonHelperGson.java From symbol-sdk-java with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(LinkedTreeMap foo, Type type, JsonSerializationContext context) { JsonObject object = new JsonObject(); TreeSet sorted = new TreeSet(foo.keySet()); for (Object key : sorted) { object.add((String) key, context.serialize(foo.get(key))); } return object; }
Example #10
Source File: ReflexDB.java From arcusplatform with Apache License 2.0 | 5 votes |
private static JsonObject convertAl(ReflexMatchAlertmeLifesign al, JsonSerializationContext context) { try { JsonObject json = new JsonObject(); json.addProperty("t", "AL"); json.addProperty("p", al.getProfile()); json.addProperty("e", al.getEndpoint()); json.addProperty("c", al.getCluster()); json.addProperty("s", al.getSetMask()); json.addProperty("u", al.getClrMask()); return json; } catch (Exception ex) { throw new RuntimeException(ex); } }
Example #11
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 #12
Source File: InvertingSourceStateSerializer.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public JsonObject serialize(final InvertingRawSourceState<?, ?> state, final Type type, final JsonSerializationContext context) { final JsonObject map = new JsonObject(); map.addProperty(NAME_KEY, state.nameProperty().get()); map.add(DEPENDS_ON_KEY, context.serialize(Arrays.stream(state.dependsOn()).mapToInt(stateToIndex).toArray())); return map; }
Example #13
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 scene ranges * * @param context Serializer context * @param ranges Allocated scene range */ private JsonElement serializeAllocatedSceneRanges(@NonNull final JsonSerializationContext context, @NonNull final List<AllocatedSceneRange> ranges) { final Type allocatedSceneRanges = new TypeToken<List<AllocatedSceneRange>>() { }.getType(); return context.serialize(ranges, allocatedSceneRanges); }
Example #14
Source File: ReflexDB.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 #15
Source File: SerializationHelpers.java From paintera with GNU General Public License v2.0 | 5 votes |
public static <T> JsonElement serializeWithClassInfo( final T object, final JsonSerializationContext context, final String typeKey, final String dataKey) { final JsonObject map = new JsonObject(); map.addProperty(typeKey, object.getClass().getName()); map.add(dataKey, context.serialize(object)); return map; }
Example #16
Source File: ReflexJson.java From arcusplatform with Apache License 2.0 | 5 votes |
private static JsonObject convertZz(ReflexActionZigbeeIasZoneEnroll zz, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("t", "ZZ"); json.addProperty("p", zz.getProfileId()); json.addProperty("e", zz.getEndpointId()); json.addProperty("c", zz.getClusterId()); return json; }
Example #17
Source File: FormulaController.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 #18
Source File: ReflexJson.java From arcusplatform with Apache License 2.0 | 5 votes |
private static JsonObject convertMg(ReflexMatchMessage mg, JsonSerializationContext context) { MessageBody msg = mg.getMessage(); MessageBody roundTrip = JSON.fromJson(JSON.toJson(msg), MessageBody.class); JsonObject json = new JsonObject(); json.addProperty("t", "MG"); json.add("m", context.serialize(roundTrip)); return json; }
Example #19
Source File: AlexaMessageFacadeSerDer.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(AlexaMessage src, Type typeOfSrc, JsonSerializationContext context) { if(src.getHeader().isV2()) { return v2.serialize(src, typeOfSrc, context); } if(src.getHeader().isV3()) { return v3.serialize(src, typeOfSrc, context); } throw new IllegalArgumentException("Invalid payload version " + src.getHeader().getPayloadVersion()); }
Example #20
Source File: AlexaMessageV2SerDer.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(AlexaMessage src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); obj.add(SerDer.ATTR_HEADER, context.serialize(src.getHeader(), Header.class)); obj.add(SerDer.ATTR_PAYLOAD, context.serialize(src.getPayload())); return obj; }
Example #21
Source File: ReflexJson.java From arcusplatform with Apache License 2.0 | 5 votes |
private static JsonObject convertZa(ReflexMatchZigbeeAttribute za, JsonSerializationContext context) { try { JsonObject json = new JsonObject(); json.addProperty("t", "ZA"); json.addProperty("r", za.getType().name()); json.addProperty("p", za.getProfile()); json.addProperty("e", za.getEndpoint()); json.addProperty("c", za.getCluster()); json.addProperty("a", za.getAttr()); Integer manuf = za.getManufacturer(); if (manuf != null) { json.addProperty("m", manuf); } Integer flags = za.getFlags(); if (flags != null) { json.addProperty("f", flags); } ZclData vl = za.getValue(); if (vl != null) { json.addProperty("v", Base64.encodeBase64String(vl.toBytes(ByteOrder.LITTLE_ENDIAN))); } return json; } catch (Exception ex) { throw new RuntimeException(ex); } }
Example #22
Source File: gson_common_serializer.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(ByteBuffer src, Type typeOfSrc, JsonSerializationContext context) { BaseEncoding encoding = BaseEncoding.base16().lowerCase(); return new JsonPrimitive(encoding.encode(src.array())); }
Example #23
Source File: gson_common_serializer.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String strResult = simpleDateFormat.format(src); return new JsonPrimitive(strResult); }
Example #24
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 #25
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; }
Example #26
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 #27
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 #28
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 #29
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 #30
Source File: LiteralRangeMultimapSerializer.java From datawave with Apache License 2.0 | 5 votes |
@Override public JsonElement serialize(Multimap<String,LiteralRange<String>> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject mm = new JsonObject(); for (Entry<String,Collection<LiteralRange<String>>> e : src.asMap().entrySet()) { JsonArray values = new JsonArray(); Collection<LiteralRange<String>> filtered = Collections2.filter(e.getValue(), Predicates.notNull()); for (LiteralRange<String> value : filtered) values.add(lrSerializer.serialize(value, typeOfSrc, context)); mm.add(e.getKey(), values); } return mm; }