当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject.fromJson方法代码示例

本文整理汇总了Java中com.couchbase.client.java.document.json.JsonObject.fromJson方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.fromJson方法的具体用法?Java JsonObject.fromJson怎么用?Java JsonObject.fromJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.couchbase.client.java.document.json.JsonObject的用法示例。


在下文中一共展示了JsonObject.fromJson方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeContact

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping(method = RequestMethod.PUT, path = "/developer/removeContact/{developerId}")
public String removeContact(final @PathVariable String developerId, final @RequestBody String json) throws Exception {
    JsonObject jsonData = JsonObject.fromJson(json);
    String contactId = jsonData.getString("contactId");

    DocumentFragment<Lookup> fragment = bucket.lookupIn(developerId).get("contacts").execute();
    JsonArray contactList = fragment.content("contacts", JsonArray.class);
    List tempList = contactList.toList();
    tempList.remove(contactId);
    contactList = JsonArray.from(tempList);
    bucket.mutateIn(developerId)
            .replace("contacts", contactList).execute();

    fragment = bucket.lookupIn(contactId).get("contacts").execute();
    contactList = fragment.content("contacts", JsonArray.class);
    tempList = contactList.toList();
    tempList.remove(developerId);
    contactList = JsonArray.from(tempList);
    bucket.mutateIn(contactId)
            .replace("contacts", contactList).execute();

    return "{}";
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:25,代码来源:IndexController.java

示例2: loadJson

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public void loadJson(Bucket bucket, String artistId) 
{
	SpotifyLoaderService loaderService = new SpotifyLoaderServiceImpl();
	
	String jsonU2Artist = loaderService.getArtist(artistId);
	
	JsonObject json = JsonObject.fromJson(jsonU2Artist);
	JsonDocument docs = JsonDocument.create("artist", json);
	bucket.upsert(docs);
	
	String jsonU2Albums = loaderService.getAlbums(artistId);
	
	json = JsonObject.fromJson(jsonU2Albums);
	docs = JsonDocument.create("albums", json);
	bucket.upsert(docs);
	
	String jsonU2RelatedArtists = loaderService.getRelatedArtists(artistId);
	
	json = JsonObject.fromJson(jsonU2RelatedArtists);
	docs = JsonDocument.create("relArtists", json);
	bucket.upsert(docs);
}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:23,代码来源:SpotifyCouchbaseLoader.java

示例3: addContact

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping(method = RequestMethod.PUT, path = "/developer/addContact/{developerId}")
public String addContact(final @PathVariable String developerId, final @RequestBody String json) throws Exception {
    JsonObject jsonData = JsonObject.fromJson(json);
    bucket.mutateIn(developerId)
            .arrayAddUnique("contacts", jsonData.getString("contactId"), true)
            .execute();
    bucket.mutateIn(jsonData.getString("contactId"))
            .arrayAddUnique("contacts", developerId, true)
            .execute();
    return "{}";
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:13,代码来源:IndexController.java

示例4: saveDeveloperInfo

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping(method = RequestMethod.PUT, path = "/developer/info/{developerId}")
public String saveDeveloperInfo(final @PathVariable String developerId, final @RequestBody String json) throws Exception {
    JsonObject jsonData = JsonObject.fromJson(json);
    bucket.mutateIn(developerId)
            .replace("developerInfo", jsonData.getObject("developerInfo"))
            .replace("address", jsonData.getObject("address"))
            .execute();
    return "{}";
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:11,代码来源:IndexController.java

示例5: upsert

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@Override
public Tt upsert(Tt tt) {
    JsonObject content = JsonObject.fromJson(gson.toJson(tt));
    content.put(DOCTYPE_KEY, DOCTYPE_TT);
    Document<?> document = JsonDocument.create(tt.getId().toString(), content);
    bucket.upsert(document);
    return tt;
}
 
开发者ID:maxcleme,项目名称:f4f-tts,代码行数:9,代码来源:CouchbaseTtsDao.java

示例6: entityToJsonDocument

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
/**
 * Transform an entity to JsonDocument
 * @param entity to transform
 * @return jsonDoc of entity
 */
protected JsonObject entityToJsonDocument(T entity){
    String json = "";
    try {
        ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
        json = ow.writeValueAsString(entity);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    JsonObject jsonObject = JsonObject.fromJson(json);
    jsonObject.removeKey("id");
    return jsonObject;
}
 
开发者ID:IsticGLA,项目名称:SIT,代码行数:18,代码来源:AbstractDAO.java

示例7: test

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
	System.out.println("Starting DB...");
	Cluster cluster = CouchbaseCluster.create();
	System.out.println("Created DB");
	System.out.println("Opening bucket...");
	Bucket bucket = cluster.openBucket("default");
	System.out.println("Opened bucket");

	int docs = 0;
	String artistId = "51Blml2LZPmy7TTiAg47vQ";
	String albumsUrl = "https://api.spotify.com/v1/artists/" + artistId + "/albums";
	System.out.println("Getting the artist's albums...");
	String albumsJson = this.getRequest(albumsUrl);
	System.out.println("Got the artist's albums...");
	docs++;
	JsonObject albumsObject = JsonObject.fromJson(albumsJson);
	String albumsId = albumsObject.getString("id");
	albumsId = albumsId == null ? "albums" + artistId : albumsId;
	JsonDocument albumsDocument = JsonDocument.create(albumsId, albumsObject);
	bucket.upsert(albumsDocument);
	JsonArray albums = albumsObject.getArray("items");
	for (Object albumObj : albums) {
		JsonObject item = (JsonObject) albumObj;
		String itemHref = item.getString("href");
		System.out.println("Getting the album...");
		String albumJson = this.getRequest(itemHref);
		System.out.println("Got the album...");
		docs++;
		JsonObject albumObject = JsonObject.fromJson(albumJson);
		String albumId = albumObject.getString("id");
		JsonDocument albumDocument = JsonDocument.create(albumId, albumObject);
		bucket.upsert(albumDocument);
		JsonArray tracks = albumObject.getObject("tracks").getArray("items");
		for (Object trackObj : tracks) {
			JsonObject track = (JsonObject) trackObj;
			String trackHref = track.getString("href");
			System.out.println("Getting the track...");
			String trackJson = this.getRequest(trackHref);
			System.out.println("Got the track...");
			docs++;
			JsonObject trackObject = JsonObject.fromJson(trackJson);
			String trackId = trackObject.getString("id");
			JsonDocument trackDocument = JsonDocument.create(trackId, trackObject);
			bucket.upsert(trackDocument);
		}
	}
	System.out.println("Total documents " + docs);
}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:50,代码来源:SpotifyRecursiveLoaderTest.java

示例8: jsonDocument

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@Test
public void jsonDocument() throws IOException {
    String doc = IOUtils.toString(this.getClass().getResourceAsStream("address.json"));
    JsonObject jo = JsonObject.fromJson(doc);
    System.out.println(jo.toString());
}
 
开发者ID:weXsol,项目名称:Couchbase,代码行数:7,代码来源:JSonTests.java

示例9: put

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
@Override
public void put(String key, String value) {
    final JsonObject jsonObject = JsonObject.fromJson(value);
    final JsonDocument document = JsonDocument.create(key, jsonObject);
    bucket.upsert(document);
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:7,代码来源:CouchbaseJsonCacheLoader.java

示例10: given_anInsertedRecordWithJson

import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
private void given_anInsertedRecordWithJson(String key, String jsonValue) {
    final JsonObject jsonObject = JsonObject.fromJson(jsonValue);
    final JsonDocument jsonDocument = JsonDocument.create(key, jsonObject);
    getBucket().upsert(jsonDocument);
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:6,代码来源:CouchbaseJsonCacheLoaderIntegrationTest.java


注:本文中的com.couchbase.client.java.document.json.JsonObject.fromJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。