@Override public JsonElement serialize(Operator op, Type type, JsonSerializationContext jsc) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(PlanExpressionConstants.CONTAINERNAME, op.containerName); jsonObject.addProperty(PlanExpressionConstants.OPERATOR, op.operator); jsonObject.addProperty(PlanExpressionConstants.OPERATORNAME, op.operatorName); if (op.queryString != null) { jsonObject.addProperty(PlanExpressionConstants.QUERYSTRING, op.queryString); } if (op.locations != null) { JsonParser parser = new JsonParser(); JsonArray locations = new JsonArray(); for (URL url : op.locations) { locations.add(parser.parse(url.toString())); } jsonObject.add(PlanExpressionConstants.LOCATIONS, locations); } if (op.paramList != null) { JsonParser parser = new JsonParser(); JsonArray params = new JsonArray(); for (Parameter param : op.paramList) { JsonArray p = new JsonArray(); p.add(parser.parse(param.name)); p.add(parser.parse(param.value)); params.add(p); } jsonObject.add(PlanExpressionConstants.PARAMETERS, params); } return jsonObject; }
@Override public JsonElement serialize(Flag flag, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("flagType", flag.flagType.name); json.addProperty("value", flag.flagType.serializeValue(flag.value)); return json; }
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. * * <p> * * <p>In the implementation of this call-back method, you should consider invoking {@link * com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to * create JsonElements for any non-trivial field of the {@code wrappedStack} object. However, you * should never invoke it on the {@code wrappedStack} object itself since that will cause an * infinite loop (Gson will call your call-back method again). * * @param wrappedStack the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @param context * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize( WrappedStack wrappedStack, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonWrappedStack = new JsonObject(); Gson gson = new Gson(); jsonWrappedStack.addProperty("type", wrappedStack.objectType); jsonWrappedStack.addProperty("stackSize", wrappedStack.stackSize); if (wrappedStack.wrappedStack instanceof ItemStack) { JsonItemStack jsonItemStack = new JsonItemStack(); jsonItemStack.itemName = Item.itemRegistry.getNameForObject(((ItemStack) wrappedStack.wrappedStack).getItem()); jsonItemStack.itemDamage = ((ItemStack) wrappedStack.wrappedStack).getItemDamage(); if (((ItemStack) wrappedStack.wrappedStack).stackTagCompound != null) { jsonItemStack.itemNBTTagCompound = ((ItemStack) wrappedStack.wrappedStack).stackTagCompound; } jsonWrappedStack.add( "objectData", JsonItemStack.jsonSerializer.toJsonTree(jsonItemStack, JsonItemStack.class)); } else if (wrappedStack.wrappedStack instanceof OreStack) { jsonWrappedStack.add( "objectData", gson.toJsonTree(wrappedStack.wrappedStack, OreStack.class)); } else if (wrappedStack.wrappedStack instanceof FluidStack) { JsonFluidStack jsonFluidStack = new JsonFluidStack((FluidStack) wrappedStack.wrappedStack); jsonWrappedStack.add( "objectData", JsonFluidStack.jsonSerializer.toJsonTree(jsonFluidStack, JsonFluidStack.class)); } return jsonWrappedStack; }
public static Response redirect( JsonObject fromPageResponse, Key rfModel, Key dataKey, boolean oobee) { JsonObject redir = new JsonObject(); redir.addProperty(MODEL_KEY, rfModel.toString()); redir.addProperty(DATA_KEY, dataKey.toString()); redir.addProperty(OOBEE, oobee); return Response.redirect(fromPageResponse, RFView.class, redir); }
@Override public String toString() { JsonObject ob = new JsonObject(); ob.addProperty("lat", this.getLat()); ob.addProperty("longitude", this.getLongitude()); ob.addProperty("base64Image", this.getBase64Encoding()); return ob.toString(); }
public JsonElement serialize( AppAudioSession src, Type typeOfSrc, JsonSerializationContext context) { JsonObject element = new JsonObject(); element.addProperty("ID", src.ID); element.addProperty("Volume", src.Volume); element.addProperty("Muted", src.Muted); return element; }
public void processMessage(String message) { JsonParser parser = new JsonParser(); JsonObject messageJSON = (JsonObject) parser.parse(message); String postedURL = messageJSON.get("postedURL").getAsString(); AlchemyAPI alchemyObj = AlchemyAPI.GetInstanceFromString("5fc91e98eacfa5ebf83440e8c6a61d0f60fa380b"); // String URLString = // "http://www.huffingtonpost.com/2015/04/05/report-vegan-diet_n_7008156.html"; System.out.println("URL sent to URLGetAuthor AlchemyAPI --> " + postedURL); Document doc = null; try { doc = alchemyObj.URLGetAuthor(postedURL); } catch (XPathExpressionException | IOException | SAXException | ParserConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String convertDocToString = getStringFromDocument(doc); // System.out.println(convertDocToString); String alchemyAPIResult = null; try { alchemyAPIResult = returnResultFromXML(convertDocToString); } catch (SAXException | IOException | ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } // System.out.println(convertDocToString); System.out.println( "Output from URLGetAuthor AlchemyAPI: Author is --> " + alchemyAPIResult.toUpperCase()); JsonObject reply = new JsonObject(); reply.addProperty("Author", alchemyAPIResult.toUpperCase()); reply.addProperty("AlchemyBackend", "JavaAPI: " + toString()); SendOptions opts = SendOptions.builder().setQos(QOS.AT_LEAST_ONCE).build(); mqlightClient.send( PUBLISH_TOPIC, reply.toString(), null, opts, new CompletionListener<Void>() { public void onSuccess(NonBlockingClient client, Void context) { logger.log(Level.INFO, "Sent reply!"); } public void onError(NonBlockingClient client, Void context, Exception exception) { logger.log(Level.INFO, "Error!." + exception.toString()); } }, null); }
private static void addFolder(FileSystem fs, Path p, JsonArray succeeded, JsonArray failed) { try { if (fs == null) return; for (FileStatus file : fs.listStatus(p)) { Path pfs = file.getPath(); if (file.isDir()) { addFolder(fs, pfs, succeeded, failed); } else { Key k = Key.make(pfs.toString()); long size = file.getLen(); Value val = null; if (pfs.getName().endsWith(Extensions.JSON)) { JsonParser parser = new JsonParser(); JsonObject json = parser.parse(new InputStreamReader(fs.open(pfs))).getAsJsonObject(); JsonElement v = json.get(Constants.VERSION); if (v == null) throw new RuntimeException("Missing version"); JsonElement type = json.get(Constants.TYPE); if (type == null) throw new RuntimeException("Missing type"); Class c = Class.forName(type.getAsString()); OldModel model = (OldModel) c.newInstance(); model.fromJson(json); } else if (pfs.getName().endsWith(Extensions.HEX)) { // Hex file? FSDataInputStream s = fs.open(pfs); int sz = (int) Math.min(1L << 20, size); // Read up to the 1st meg byte[] mem = MemoryManager.malloc1(sz); s.readFully(mem); // Convert to a ValueArray (hope it fits in 1Meg!) ValueArray ary = new ValueArray(k, 0).read(new AutoBuffer(mem)); val = new Value(k, ary, Value.HDFS); } else if (size >= 2 * ValueArray.CHUNK_SZ) { val = new Value( k, new ValueArray(k, size), Value.HDFS); // ValueArray byte wrapper over a large file } else { val = new Value(k, (int) size, Value.HDFS); // Plain Value val.setdsk(); } DKV.put(k, val); Log.info("PersistHdfs: DKV.put(" + k + ")"); JsonObject o = new JsonObject(); o.addProperty(Constants.KEY, k.toString()); o.addProperty(Constants.FILE, pfs.toString()); o.addProperty(Constants.VALUE_SIZE, file.getLen()); succeeded.add(o); } } } catch (Exception e) { Log.err(e); JsonObject o = new JsonObject(); o.addProperty(Constants.FILE, p.toString()); o.addProperty(Constants.ERROR, e.getMessage()); failed.add(o); } }
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. * * <p> * * <p>In the implementation of this call-back method, you should consider invoking {@link * com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to * create JsonElements for any non-trivial field of the {@code energyValueObject} object. However, * you should never invoke it on the {@code energyValueObject} object itself since that will cause * an infinite loop (Gson will call your call-back method again). * * @param energyValueObject the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @param context * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize( EnergyValue energyValueObject, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonEnergyValue = new JsonObject(); jsonEnergyValue.addProperty("type", energyValueObject.energyType.ordinal()); jsonEnergyValue.addProperty("value", energyValueObject.energyValue); return jsonEnergyValue; }
@Override public JsonElement serialize( Transaction transaction, Type type, JsonSerializationContext jsonSerializationContext) { final JsonObject jo = new JsonObject(); jo.addProperty("amount", transaction.getAmount()); jo.addProperty("type", transaction.getType()); if (transaction.getParent() != null) { jo.addProperty("parent", transaction.getParent().getId()); } return jo; }
public static void addFolder(Path p, JsonArray succeeded, JsonArray failed) throws IOException { FileSystem fs = FileSystem.get(p.toUri(), PersistHdfs.CONF); if (!fs.exists(p)) { JsonObject o = new JsonObject(); o.addProperty(Constants.FILE, p.toString()); o.addProperty(Constants.ERROR, "Path does not exist!"); failed.add(o); return; } addFolder(fs, p, succeeded, failed); }
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 JsonObject toJson() { JsonObject res = new JsonObject(); res.addProperty(Constants.VERSION, H2O.VERSION); res.addProperty(Constants.TYPE, KMeansModel.class.getName()); res.addProperty(Constants.ERROR, _error); JsonArray ary = new JsonArray(); for (double[] dd : clusters()) { JsonArray ary2 = new JsonArray(); for (double d : dd) ary2.add(new JsonPrimitive(d)); ary.add(ary2); } res.add(Constants.CLUSTERS, ary); return res; }
@Override public JsonElement serialize( WrappedStack wrappedStack, Type type, JsonSerializationContext context) { JsonObject jsonWrappedStack = new JsonObject(); Gson gsonWrappedStack = new Gson(); jsonWrappedStack.addProperty("className", wrappedStack.className); jsonWrappedStack.addProperty("stackSize", wrappedStack.stackSize); if (wrappedStack.wrappedStack instanceof ItemStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, ItemStack.class)); } else if (wrappedStack.wrappedStack instanceof OreStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, OreStack.class)); } else if (wrappedStack.wrappedStack instanceof EnergyStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, EnergyStack.class)); } else if (wrappedStack.wrappedStack instanceof FluidStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, FluidStack.class)); } return jsonWrappedStack; }
@Override public JsonElement serialize( OutputDataRaw cellRaw, Type typeOfSrc, JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); if (cellRaw.png != null) { jsonObject.addProperty("image/png", cellRaw.png); } if (cellRaw.html != null) { final JsonElement html = gson.toJsonTree(cellRaw.html); jsonObject.add("text/html", html); } if (cellRaw.svg != null) { final JsonElement svg = gson.toJsonTree(cellRaw.svg); jsonObject.add("image/svg+xml", svg); } if (cellRaw.jpeg != null) { final JsonElement jpeg = gson.toJsonTree(cellRaw.jpeg); jsonObject.add("image/jpeg", jpeg); } if (cellRaw.latex != null) { final JsonElement latex = gson.toJsonTree(cellRaw.latex); jsonObject.add("text/latex", latex); } if (cellRaw.text != null) { final JsonElement text = gson.toJsonTree(cellRaw.text); jsonObject.add("text/plain", text); } return jsonObject; }
@Override public JsonObject exportToJson() { JsonObject json = new JsonObject(); if (canRandomize) { json.addProperty("shouldRandomize", shouldRandomize); } return json; }
public void processListing(ObjectListing listing, JsonArray succ, JsonArray fail) { for (S3ObjectSummary obj : listing.getObjectSummaries()) { try { Key k = PersistS3.loadKey(obj); JsonObject o = new JsonObject(); o.addProperty(KEY, k.toString()); o.addProperty(FILE, obj.getKey()); o.addProperty(VALUE_SIZE, obj.getSize()); succ.add(o); } catch (IOException e) { JsonObject o = new JsonObject(); o.addProperty(FILE, obj.getKey()); o.addProperty(ERROR, e.getMessage()); fail.add(o); } } }
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); } }
@Override public JsonElement serialize( IpnbCellRaw cellRaw, Type typeOfSrc, JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("cell_type", cellRaw.cell_type); if ("code".equals(cellRaw.cell_type)) { final Integer count = cellRaw.execution_count; if (count == null) { jsonObject.add("execution_count", JsonNull.INSTANCE); } else { jsonObject.addProperty("execution_count", count); } } if (cellRaw.metadata != null) { final JsonElement metadata = gson.toJsonTree(cellRaw.metadata); jsonObject.add("metadata", metadata); } if (cellRaw.level != null) { jsonObject.addProperty("level", cellRaw.level); } if (cellRaw.outputs != null) { final JsonElement outputs = gson.toJsonTree(cellRaw.outputs); jsonObject.add("outputs", outputs); } if (cellRaw.source != null) { final JsonElement source = gson.toJsonTree(cellRaw.source); jsonObject.add("source", source); } if (cellRaw.input != null) { final JsonElement input = gson.toJsonTree(cellRaw.input); jsonObject.add("input", input); } if (cellRaw.language != null) { jsonObject.addProperty("language", cellRaw.language); } if (cellRaw.prompt_number != null) { jsonObject.addProperty("prompt_number", cellRaw.prompt_number); } return jsonObject; }
@Override public JsonElement serialize(FailureMirror e, Type type, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("throwableClass", e.getThrowableClass()); object.addProperty("throwableString", e.getThrowableString()); object.addProperty("stackTrace", e.getTrace()); String throwableKind; if (e.isAssertionViolation()) { throwableKind = "assertion"; } else if (e.isErrorViolation()) { throwableKind = "error"; } else if (e.isAssumptionViolation()) { throwableKind = "assumption"; } else { throwableKind = "unknown"; } object.addProperty("kind", throwableKind); return object; }
@Override public JsonElement serialize( IpnbFileRaw fileRaw, Type typeOfSrc, JsonSerializationContext context) { final JsonObject jsonObject = new JsonObject(); if (fileRaw.worksheets != null) { final JsonElement worksheets = gson.toJsonTree(fileRaw.worksheets); jsonObject.add("worksheets", worksheets); } if (fileRaw.cells != null) { final JsonElement cells = gson.toJsonTree(fileRaw.cells); jsonObject.add("cells", cells); } final JsonElement metadata = gson.toJsonTree(fileRaw.metadata); jsonObject.add("metadata", metadata); jsonObject.addProperty("nbformat", fileRaw.nbformat); jsonObject.addProperty("nbformat_minor", fileRaw.nbformat_minor); return jsonObject; }
static void modified() { try (FileWriter writer = new FileWriter(getFile())) { JsonObject obj = deepCopy(INSTANCE.everythingElse); obj.addProperty("clientToken", INSTANCE.clientToken); obj.add("authenticationDatabase", GSON.toJsonTree(INSTANCE.authenticationDatabase.profiles)); GSON.toJson(obj, writer); System.out.println("Profiles saved"); } catch (IOException e) { e.printStackTrace(); } }
@Override public JsonElement serialize( DeviceIconType deviceIcon, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonDeviceIconType = new JsonObject(); for (Position.Status status : Position.Status.values()) { PositionIconType positionIcon = deviceIcon.getPositionIconType(status); JsonObject jsonPositionIconType = new JsonObject(); jsonPositionIconType.addProperty("width", positionIcon.getWidth()); jsonPositionIconType.addProperty("height", positionIcon.getHeight()); JsonArray urls = new JsonArray(); urls.add(new JsonPrimitive(positionIcon.getURL(false))); urls.add(new JsonPrimitive(positionIcon.getURL(true))); jsonPositionIconType.add("urls", urls); jsonDeviceIconType.add(status.name(), jsonPositionIconType); } return jsonDeviceIconType; }
protected JsonObject defaultJsonResponse() { // This will be shown every request JsonObject r = new JsonObject(); RFModel model = _modelKey.value(); r.addProperty(DATA_KEY, _dataKey.originalValue()); r.addProperty(MODEL_KEY, _modelKey.originalValue()); r.addProperty(CLASS, _classCol.specified() ? _classCol.value() : findResponseIdx(model)); r.addProperty(NUM_TREES, model._totalTrees); r.addProperty(MTRY, model._splitFeatures); r.addProperty(MTRY_NODES, Arrays.toString(model._nodesSplitFeatures)); r.addProperty(OOBEE, _oobee.value()); // CM specific options r.addProperty(NO_CM, _noCM.value()); r.addProperty(JSON_REFRESH_THRESHOLD_CM, _refreshThresholdCM.value()); return r; }
public static Response redirect( JsonObject fromPageResponse, Key jobKey, Key modelKey, Key dataKey, int ntree, int classCol, String weights, boolean oobee, boolean iterativeCM) { JsonObject redirect = new JsonObject(); if (jobKey != null) redirect.addProperty(JOB, jobKey.toString()); redirect.addProperty(MODEL_KEY, modelKey.toString()); redirect.addProperty(DEST_KEY, modelKey.toString()); redirect.addProperty(DATA_KEY, dataKey.toString()); redirect.addProperty(NUM_TREES, ntree); redirect.addProperty(CLASS, classCol); if (weights != null) redirect.addProperty(WEIGHTS, weights); redirect.addProperty(OOBEE, oobee); redirect.addProperty(ITERATIVE_CM, iterativeCM); return Response.redirect(fromPageResponse, RFView.class, redirect); }
@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; }
public JsonObject traversePS(SiebelPropertySet ps, JsonObject jObj) { JsonObject siebJSON = new JsonObject(); String propName; String propVal; propName = ps.getFirstProperty(); while (propName != "") { propVal = ps.getProperty(propName); siebJSON.addProperty(propName, propVal); propName = ps.getNextProperty(); } JsonObject child; for (int i = 0; i < ps.getChildCount(); i++) { child = new JsonObject(); child = traversePS(ps.getChild(i), child); siebJSON.add(ps.getChild(i).getType(), child); } return siebJSON; }
@Override public JsonElement serialize( WrappedStack wrappedStack, Type type, JsonSerializationContext context) { JsonObject jsonWrappedStack = new JsonObject(); Gson gsonWrappedStack = new Gson(); jsonWrappedStack.addProperty("className", wrappedStack.className); jsonWrappedStack.addProperty("stackSize", wrappedStack.stackSize); if (wrappedStack.wrappedStack instanceof ItemStack) { JsonItemStack jsonItemStack = new JsonItemStack(); jsonItemStack.itemID = ((ItemStack) wrappedStack.wrappedStack).itemID; jsonItemStack.itemDamage = ((ItemStack) wrappedStack.wrappedStack).getItemDamage(); jsonItemStack.stackSize = ((ItemStack) wrappedStack.wrappedStack).stackSize; if (((ItemStack) wrappedStack.wrappedStack).stackTagCompound != null) { try { jsonItemStack.compressedStackTagCompound = CompressedStreamTools.compress( ((ItemStack) wrappedStack.wrappedStack).stackTagCompound); } catch (IOException e) { e.printStackTrace(); } } jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(jsonItemStack, JsonItemStack.class)); } else if (wrappedStack.wrappedStack instanceof OreStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, OreStack.class)); } else if (wrappedStack.wrappedStack instanceof EnergyStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, EnergyStack.class)); } else if (wrappedStack.wrappedStack instanceof FluidStack) { jsonWrappedStack.add( "wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, FluidStack.class)); } return jsonWrappedStack; }
private static JsonElement dumpConfig(Table<String, String, IConfigPropertyHolder> properties) { JsonObject result = new JsonObject(); Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().serializeNulls().create(); for (Map.Entry<String, Map<String, IConfigPropertyHolder>> category : properties.rowMap().entrySet()) { JsonObject categoryNode = new JsonObject(); for (Map.Entry<String, IConfigPropertyHolder> property : category.getValue().entrySet()) { JsonObject propertyNode = new JsonObject(); IConfigPropertyHolder propertyHolder = property.getValue(); final String comment = propertyHolder.comment(); if (!Strings.isNullOrEmpty(comment)) propertyNode.addProperty(COMMENT_TAG, comment); try { Object value = propertyHolder.getValue(); JsonElement serialized = gson.toJsonTree(value); propertyNode.add(VALUE_TAG, serialized); } catch (Exception e) { Log.warn( e, "Failed to serialize property %s:%s", propertyHolder.category(), propertyHolder.name()); } categoryNode.add(property.getKey(), propertyNode); } result.add(category.getKey(), categoryNode); } return result; }
@Override public JsonElement serialize( DeviceOption[] src, Type typeOfSrc, JsonSerializationContext context) { JsonArray jsonObject = new JsonArray(); for (DeviceOption option : src) { JsonObject newObject = new JsonObject(); newObject.addProperty("property", option.getProperty()); newObject.addProperty("name", option.getName()); newObject.addProperty("description", option.getDescription()); newObject.addProperty("readonly", option.isReadOnly()); newObject.addProperty("type", option.getType().toString()); JsonArray newArray = new JsonArray(); for (String value : option.getValidValues()) { newArray.add(value); } newObject.add("validValues", newArray); if (option.isArray()) { newArray = new JsonArray(); for (String value : option.getArrayValue()) { newArray.add(value); } newObject.add("values", newArray); } else { newObject.addProperty("value", option.getValue()); } jsonObject.add(newObject); } return jsonObject; }