List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:buri.ddmsence.ddms.summary.TemporalCoverage.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() *//* www.j av a 2 s . c om*/ public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, TIME_PERIOD_NAME_NAME, getTimePeriodName()); addJson(object, START_NAME, getStartString()); addJson(object, END_NAME, getEndString()); addJson(object, getApproximableStart()); addJson(object, getApproximableEnd()); addJson(object, getSecurityAttributes()); return (object); }
From source file:buri.ddmsence.ddms.summary.VerticalExtent.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() *//*from w w w . j a v a 2s . c om*/ public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, UOM_NAME, getUnitOfMeasure()); addJson(object, DATUM_NAME, getDatum()); addJson(object, "minimum", getMinVerticalExtent()); addJson(object, "maximum", getMaxVerticalExtent()); return (object); }
From source file:buri.ddmsence.ddms.summary.VirtualCoverage.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() *///from w w w.j a v a 2 s .c o m public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, ADDRESS_NAME, getAddress()); addJson(object, PROTOCOL_NAME, getProtocol()); addJson(object, ACCESS_NAME, getAccess()); addJson(object, NETWORK_NAME, getNetwork()); addJson(object, getSecurityAttributes()); return (object); }
From source file:buri.ddmsence.ddms.summary.xlink.XLinkAttributes.java
License:Open Source License
/** * @see AbstractAttributeGroup#getJSONObject() *///from ww w . j ava 2 s .co m public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, TYPE_NAME, getType()); addJson(object, HREF_NAME, getHref()); addJson(object, ROLE_NAME, getRole()); addJson(object, TITLE_NAME, getTitle()); addJson(object, LABEL_NAME, getLabel()); addJson(object, ARC_ROLE_NAME, getArcrole()); addJson(object, SHOW_NAME, getShow()); addJson(object, ACTUATE_NAME, getActuate()); return (object); }
From source file:business.DataGenerator.java
public String getData(int amount, String properties) { JsonArray names = new JsonArray(); JsonObject person = new JsonObject(); Gson gson = new Gson(); for (int i = 0; i < amount; i++) { person = new JsonObject(); if (properties.contains("fname")) { person.addProperty("fname", fnames.get(new Random().nextInt(6))); }/*from www . j a v a2s .com*/ if (properties.contains("lname")) { person.addProperty("lname", lnames.get(new Random().nextInt(6))); } if (properties.contains("street")) { person.addProperty("street", streets.get(new Random().nextInt(7))); } if (properties.contains("city")) { person.addProperty("city", cities.get(new Random().nextInt(7))); } // System.out.println(i+") "+gson.toJson(person)); names.add(person); } String jsonStr = gson.toJson(names); return jsonStr; }
From source file:ca.paullalonde.gocd.sns_plugin.executors.GetViewRequestExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("template", Util.readResource("/plugin-settings.template.html")); DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200); defaultGoPluginApiResponse.setResponseBody(GSON.toJson(jsonObject)); return defaultGoPluginApiResponse; }
From source file:ca.paullalonde.gocd.sns_plugin.executors.NotificationInterestedInExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); JsonArray notifications = new JsonArray(); notifications.add(REQUEST_STAGE_STATUS.requestName()); jsonObject.add("notifications", notifications); DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200); defaultGoPluginApiResponse.setResponseBody(GSON.toJson(jsonObject)); return defaultGoPluginApiResponse; }
From source file:ca.ualberta.cmput301w14t08.geochan.json.BitmapJsonConverter.java
License:Apache License
/** * Serializes a Bitmap to a base64 JSON string. * //from w w w. ja v a 2 s .co m * @param bitmap * the Bitmap to serialize * @param type * the type * @param jsc * the JSON serialization context * * @return a JsonElement representing the serialized Bitmap. */ @Override public JsonElement serialize(Bitmap bitmap, Type type, JsonSerializationContext jsc) { JsonObject object = new JsonObject(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); String encoded = Base64.encodeToString(byteArray, Base64.NO_WRAP); object.addProperty("image", encoded); return object; }
From source file:ca.ualberta.cmput301w14t08.geochan.json.CommentJsonConverter.java
License:Apache License
/** * Serializes a Comment object into JSON format. * /*www.ja va 2 s . c o m*/ * @param comment * the Comment to serialize * @param type * the Type * @param context * the JSON serialization context * * @return A JsonElement representing the serialized Comment. */ @Override public JsonElement serialize(Comment comment, Type type, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("commentDate", comment.getCommentDate().getTime()); if (comment.getLocation() != null) { object.addProperty("location", comment.getLocation().getLatitude() + "," + comment.getLocation().getLongitude()); if (comment.getLocation().getLocationDescription() != null) { object.addProperty("locationDescription", comment.getLocation().getLocationDescription()); } } else { object.addProperty("location", "-999,-999"); } object.addProperty("user", comment.getUser()); object.addProperty("hash", comment.getHash()); object.addProperty("id", comment.getId()); object.addProperty("textPost", comment.getTextPost()); object.addProperty("hasImage", comment.hasImage()); if (comment.hasImage()) { /* * http://stackoverflow.com/questions/9224056/android-bitmap-to-base64 * -string * * Serialize just the thumbnail as the image is serialized * separately */ Bitmap bitmapThumb = comment.getImageThumb(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmapThumb.compress(Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream); byte[] byteThumbArray = byteArrayOutputStream.toByteArray(); String encodedThumb = Base64.encodeToString(byteThumbArray, Base64.NO_WRAP); object.addProperty("imageThumbnail", encodedThumb); } object.addProperty("depth", comment.getDepth()); if (comment.getParent() != null) { object.addProperty("parent", comment.getParent().getId()); } return object; }
From source file:ca.ualberta.cmput301w14t08.geochan.json.CommentOfflineJsonConverter.java
License:Apache License
/** * Serializes a Comment object into JSON format (for offline storage). * /*ww w . j ava2 s . c o m*/ * @param comment * the Comment to serialize * @param type * the Type * @param context * the JSON serialization context * * @return A JsonElement representing the serialized Comment. */ @Override public JsonElement serialize(Comment comment, Type type, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("commentDate", comment.getCommentDate().getTime()); if (comment.getLocation() != null) { object.addProperty("location", comment.getLocation().getLatitude() + "," + comment.getLocation().getLongitude()); if (comment.getLocation().getLocationDescription() != null) { object.addProperty("locationDescription", comment.getLocation().getLocationDescription()); } } else { object.addProperty("location", "-999,-999"); } object.addProperty("user", comment.getUser()); object.addProperty("hash", comment.getHash()); object.addProperty("id", comment.getId()); object.addProperty("textPost", comment.getTextPost()); object.addProperty("hasImage", comment.hasImage()); if (comment.hasImage()) { Bitmap bitmapThumb = comment.getImageThumb(); /* * http://stackoverflow.com/questions/9224056/android-bitmap-to-base64 * -string * * Serialize just the thumbnail as the image is serialized * separately */ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmapThumb.compress(Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream); byte[] byteThumbArray = byteArrayOutputStream.toByteArray(); String encodedThumb = Base64.encodeToString(byteThumbArray, Base64.NO_WRAP); object.addProperty("imageThumbnail", encodedThumb); } object.addProperty("depth", comment.getDepth()); if (comment.getParent() != null) { object.addProperty("parent", comment.getParent().getId()); } return object; }