List of usage examples for com.google.gson JsonSerializationContext serialize
public JsonElement serialize(Object src);
From source file:org.restcomm.sbc.rest.converter.BanListListConverter.java
License:Open Source License
@Override public JsonObject serialize(BanListList banListList, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); JsonArray array = new JsonArray(); for (BanList banList : banListList.getBanListList()) { array.add(context.serialize(banList)); }//from w w w . j a va2s .co m if (total != null && pageSize != null && page != null) { result.addProperty("page", page); result.addProperty("num_pages", getTotalPages()); result.addProperty("page_size", pageSize); result.addProperty("total", total); result.addProperty("start", getFirstIndex()); result.addProperty("end", getLastIndex(banListList)); result.addProperty("uri", pathUri); result.addProperty("first_page_uri", getFirstPageUri()); result.addProperty("previous_page_uri", getPreviousPageUri()); result.addProperty("next_page_uri", getNextPageUri(banListList)); result.addProperty("last_page_uri", getLastPageUri()); } result.add("entries", array); return result; }
From source file:org.restcomm.sbc.rest.converter.ConnectorListConverter.java
License:Open Source License
@Override public JsonObject serialize(ConnectorList connectorList, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); JsonArray array = new JsonArray(); for (Connector connector : connectorList.getConnectorList()) { array.add(context.serialize(connector)); }//w ww.java 2s . com result.add("entries", array); return result; }
From source file:org.restcomm.sbc.rest.converter.LocationsListConverter.java
License:Open Source License
@Override public JsonObject serialize(LocationList locationList, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); JsonArray array = new JsonArray(); for (Location location : locationList.getLocations()) { array.add(context.serialize(location)); }//from w w w . ja va 2s . co m if (total != null && pageSize != null && page != null) { result.addProperty("page", page); result.addProperty("num_pages", getTotalPages()); result.addProperty("page_size", pageSize); result.addProperty("total", total); result.addProperty("start", getFirstIndex()); result.addProperty("end", getLastIndex(locationList)); result.addProperty("uri", pathUri); result.addProperty("first_page_uri", getFirstPageUri()); result.addProperty("previous_page_uri", getPreviousPageUri()); result.addProperty("next_page_uri", getNextPageUri(locationList)); result.addProperty("last_page_uri", getLastPageUri()); } result.add("locations", array); return result; }
From source file:org.restcomm.sbc.rest.converter.MonitoringServiceConverter.java
License:Open Source License
@Override public JsonElement serialize(MonitoringServiceResponse monitoringServiceResponse, Type typeOfSrc, JsonSerializationContext context) { Map<String, Integer> countersMap = monitoringServiceResponse.getCountersMap(); JsonObject result = new JsonObject(); JsonObject metrics = new JsonObject(); JsonArray callsArray = new JsonArray(); if (logger.isInfoEnabled()) { logger.info("MonitoringServiceConverter " + monitoringServiceResponse); }//from w w w . j a v a2s . c o m //First add InstanceId and Version details //result.addProperty("InstanceId", monitoringServiceResponse.getInstanceId().getId().toString()); result.addProperty("Version", org.restcomm.sbc.Version.getVersion()); result.addProperty("Revision", org.restcomm.sbc.Version.getRevision()); Iterator<String> counterIterator = countersMap.keySet().iterator(); while (counterIterator.hasNext()) { String counter = counterIterator.next(); metrics.addProperty(counter, countersMap.get(counter)); } result.add("Metrics", metrics); if (monitoringServiceResponse.getCallDetailsList().size() > 0) for (Call callInfo : monitoringServiceResponse.getCallDetailsList()) { callsArray.add(context.serialize(callInfo)); } result.add("LiveCallDetails", callsArray); return result; }
From source file:org.restcomm.sbc.rest.converter.NetworkPointListConverter.java
License:Open Source License
@Override public JsonObject serialize(NetworkPointList pointList, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); JsonArray array = new JsonArray(); for (NetworkPoint point : pointList.getNetworkPointList()) { array.add(context.serialize(point)); }//from w ww. j a v a2s. c om result.add("entries", array); return result; }
From source file:org.restcomm.sbc.rest.converter.RouteListConverter.java
License:Open Source License
@Override public JsonObject serialize(RouteList routeList, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); JsonArray array = new JsonArray(); for (Route route : routeList.getRouteList()) { array.add(context.serialize(route)); }/* w w w .j a v a 2 s .c o m*/ result.add("entries", array); return result; }
From source file:org.restcomm.sbc.rest.converter.StatisticsListConverter.java
License:Open Source License
@Override public JsonObject serialize(StatisticsList routeList, Type type, JsonSerializationContext context) { JsonObject result = new JsonObject(); JsonArray array = new JsonArray(); for (Statistics route : routeList.getStatisticsList()) { array.add(context.serialize(route)); }//ww w .ja v a 2 s . c om result.add("entries", array); return result; }
From source file:org.robovm.junit.protocol.DescriptionTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(Description description, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject jsonObject = new JsonObject(); jsonObject.add("display_name", new JsonPrimitive(description.getDisplayName())); ArrayList<Description> subDescription = description.getChildren(); JsonArray array = new JsonArray(); for (Description desc : subDescription) { array.add(jsonSerializationContext.serialize(desc)); }/* w ww .java2 s. co m*/ jsonObject.add("sub_description", array); return jsonObject; }
From source file:org.scassandra.http.client.types.GsonExactMatchSerialiser.java
License:Apache License
@Override public JsonElement serialize(MultiPrimeRequest.ExactMatch src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = new JsonObject(); jsonObject.add("matcher", context.serialize(src.matcher())); jsonObject.addProperty("type", src.type().toString()); return jsonObject; }
From source file:org.smartparam.manager.json.vendor.gson.DescribedCollectionSerializer.java
License:Apache License
@Override public JsonElement serialize(DescribedCollection collection, Type type, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.add("source", context.serialize(collection.source())); object.add("items", context.serialize(collection.items())); return object; }