List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
From source file:com.claresco.tinman.json.XapiCredentialsJson.java
License:Open Source License
@Override public JsonElement serialize(XapiCredentials arg0, Type arg1, JsonSerializationContext arg2) { JsonObject theResult = new JsonObject(); theResult.add(ACTORS, arg2.serialize(arg0.getPerson(), XapiPerson.class)); theResult.add(HISTORICAL, new JsonPrimitive(arg0.getHistorical())); theResult.add(SCOPE, JsonUtility.convertToJsonArray(arg0.getScope())); theResult.addProperty(EXPIRY, arg0.getExpiry().toString()); if (arg0.hasRegistration()) { theResult.addProperty(REGISTRATION, arg0.getRegistration().toString()); }/*from www. ja v a 2 s .co m*/ if (arg0.hasActivityIDs()) { theResult.add(ACTIVITY, JsonUtility.convertToJsonArrayFromIRIList(arg0.getActivityIDs())); } return theResult; }
From source file:com.claresco.tinman.servlet.XapiServletUtility.java
License:Open Source License
protected static String createJsonArray(ArrayList<String> theData) { JsonArray theArray = new JsonArray(); for (String s : theData) { theArray.add(new JsonPrimitive(s)); }/*from w ww. j a v a 2 s .c om*/ return theArray.toString(); }
From source file:com.claresco.tinman.servlet.XapiServletUtility.java
License:Open Source License
protected static String createJsonArray(Set<String> theData) { JsonArray theArray = new JsonArray(); for (String s : theData) { theArray.add(new JsonPrimitive(s)); }// w ww .j a va2s . c om return theArray.toString(); }
From source file:com.cloud.agent.transport.VolListTypeAdaptor.java
License:Open Source License
public JsonElement serialize(List<VolumeVO> src, Type typeOfSrc, JsonSerializationContext context) { Gson json = s_gBuilder.create();/* w w w.j a va2s .com*/ String result = json.toJson(src, listType); return new JsonPrimitive(result); }
From source file:com.cloud.api.EncodedStringTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(String src, Type typeOfResponseObj, JsonSerializationContext ctx) { return new JsonPrimitive(encodeString(src)); }
From source file:com.cloud.api.IdentityTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(IdentityProxy src, Type srcType, JsonSerializationContext context) { if (SerializationContext.current().getUuidTranslation()) { assert (src != null); if (src.getValue() == null) return context.serialize(null); IdentityDao identityDao = new IdentityDaoImpl(); if (src.getTableName() != null) { String uuid = identityDao.getIdentityUuid(src.getTableName(), String.valueOf(src.getValue())); if (uuid == null) return context.serialize(null); // Exceptions set the _idFieldName in the IdentityProxy structure. So if this field is not // null, prepare a structure of uuid and idFieldName and return the json representation of that. String idName = src.getidFieldName(); if (idName != null) { // Prepare a structure. JsonObject jsonObj = new JsonObject(); jsonObj.add("uuid", new JsonPrimitive(uuid)); jsonObj.add("uuidProperty", new JsonPrimitive(idName)); return jsonObj; }// w w w .j ava 2s . c o m return new JsonPrimitive(uuid); } else { return new JsonPrimitive(String.valueOf(src.getValue())); } } else { return new Gson().toJsonTree(src); } }
From source file:com.cloudant.client.api.Database.java
License:Open Source License
/** * Set permissions for a user/apiKey on this database. * <p>// ww w .ja va2 s. c o m * Note this method is only applicable to databases that support the * <a href="http://docs.cloudant.com/authorization.html"> * Cloudant authorization API * </a> such as Cloudant DBaaS. For unsupported databases consider using the /db/_security * endpoint. * </p> * * @param userNameorApikey * @param permissions permissions to grant * @throws UnsupportedOperationException if called on a database that does not provide the * Cloudant authorization API * @see <a href="http://docs.cloudant.com/authorization.html#roles">Roles</a> * @see <a href="http://docs.cloudant.com/authorization.html#modifying-permissions">Modifying * permissions</a> */ public void setPermissions(String userNameorApikey, EnumSet<Permissions> permissions) { assertNotEmpty(userNameorApikey, "userNameorApikey"); assertNotEmpty(permissions, "permissions"); final JsonArray jsonPermissions = new JsonArray(); for (Permissions s : permissions) { final JsonPrimitive permission = new JsonPrimitive(s.toString()); jsonPermissions.add(permission); } // get existing permissions JsonObject perms = getPermissionsObject(); // now set back JsonElement elem = perms.get("cloudant"); if (elem == null) { perms.addProperty("_id", "_security"); elem = new JsonObject(); perms.add("cloudant", elem); } elem.getAsJsonObject().add(userNameorApikey, jsonPermissions); HttpResponse response = null; HttpPut put = new HttpPut(apiV2DBSecurityURI); setEntity(put, client.getGson().toJson(perms), "application/json"); try { response = executeRequest(put); String ok = getAsString(response, "ok"); if (!ok.equalsIgnoreCase("true")) { //raise exception } } finally { close(response); } }
From source file:com.cloudant.client.api.DatabaseImpl.java
License:Open Source License
@Override public void setPermissions(String userNameorApikey, EnumSet<Permissions> permissions) { assertNotEmpty(userNameorApikey, "userNameorApikey"); assertNotEmpty(permissions, "permissions"); final JsonArray jsonPermissions = new JsonArray(); for (Permissions s : permissions) { final JsonPrimitive permission = new JsonPrimitive(s.toString()); jsonPermissions.add(permission); }/*from w w w . ja v a 2 s . co m*/ // get existing permissions JsonObject perms = getPermissionsObject(); // now set back JsonElement elem = perms.get("cloudant"); if (elem == null) { perms.addProperty("_id", "_security"); elem = new JsonObject(); perms.add("cloudant", elem); } elem.getAsJsonObject().add(userNameorApikey, jsonPermissions); InputStream response = null; HttpConnection put = Http.PUT(apiV2DBSecurityURI, "application/json"); put.setRequestBody(client.getGson().toJson(perms)); try { response = client.couchDbClient.executeToInputStream(put); String ok = getAsString(response, "ok"); if (!ok.equalsIgnoreCase("true")) { //raise exception } } finally { close(response); } }
From source file:com.cloudant.client.api.model.FindByIndexOptions.java
License:Open Source License
/** * Specify a specific index to run the query against * * @param designDocument set the design document to use * @return this to set additional options *//*from w w w. j av a 2 s. c o m*/ public FindByIndexOptions useIndex(String designDocument) { assertNotNull(designDocument, "designDocument"); this.useIndex = new JsonPrimitive(designDocument); return this; }
From source file:com.cloudant.client.api.model.FindByIndexOptions.java
License:Open Source License
/** * Specify a specific index to run the query against * * @param designDocument set the design document to use * @param indexName set the index name to use * @return this to set additional options *//*w w w . j a v a 2 s. co m*/ public FindByIndexOptions useIndex(String designDocument, String indexName) { assertNotNull(designDocument, "designDocument"); assertNotNull(indexName, "indexName"); JsonArray index = new JsonArray(); index.add(new JsonPrimitive(designDocument)); index.add(new JsonPrimitive(indexName)); this.useIndex = index; return this; }