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


Java Gson.toJsonTree方法代码示例

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


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

示例1: mapToJson

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * Method of converting hashmap to JSON
 *
 * @param word        input query
 * @param wordweights a map from related terms to weights
 * @return converted JSON object
 */
private JsonObject mapToJson(Map<String, Double> wordweights) {
  Gson gson = new Gson();
  JsonObject json = new JsonObject();
  List<JsonObject> nodes = new ArrayList<>();

  for (Entry<String, Double> entry : wordweights.entrySet()) {
    JsonObject node = new JsonObject();
    String key = entry.getKey();
    Double value = entry.getValue();
    node.addProperty("word", key);
    node.addProperty("weight", value);
    nodes.add(node);
  }

  JsonElement nodesElement = gson.toJsonTree(nodes);
  json.add("ontology", nodesElement);

  return json;
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:27,代码来源:LinkageIntegration.java

示例2: toJson

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public JsonObject toJson() {
    Gson gson = new Gson();
    Data data = new Data(this);
    JsonElement jsonElement = gson.toJsonTree(data);
    return jsonElement.getAsJsonObject();
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:8,代码来源:LiBasePostModel.java

示例3: testSerialization

import com.google.gson.Gson; //导入方法依赖的package包/类
@Test
public void testSerialization() {
    Gson gson = getGSON(getFactory(t -> "foo", emptyList(), emptyList()));
    SubTypeA typeA = new SubTypeA();
    typeA.foo = 1;
    typeA.bar = "t1";
    typeA.baz = "t2";

    JsonElement actual = gson.toJsonTree(typeA, new TypeToken<Base>() { }.getType());
    JsonElement expected = new JsonParser().parse(makeJSON(1, "t1", "t2"));
    Assert.assertEquals(actual, expected);

    SubTypeB typeB = new SubTypeB();
    typeB.foo = 2;
    typeB.bar = "t2";
    typeB.qux = asList("a", "b");

    actual = gson.toJsonTree(typeB, new TypeToken<Base>() { }.getType());
    expected = new JsonParser().parse(makeJSON(2, "t2", asList("a", "b")));
    Assert.assertEquals(actual, expected);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:22,代码来源:FieldTypeAdapterFactoryTest.java

示例4: getBaseLearnerJsonObject

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * The utility method to create json object for evaluation metric in the json configuration.
 * 
 * @param baseLearnerObject the list of evaluation metric elements
 * @return the json object of the evaluation metric
 */
public static JsonObject getBaseLearnerJsonObject(BaseLearnerJsonObjectCreator baseLearnerObject) {
   Gson gson = new GsonBuilder().create();
   JsonElement baseLearners = gson.toJsonTree(baseLearnerObject);
   JsonObject jsonObject = new JsonObject();
   jsonObject.add(PARAMETER_BASELEARNER, baseLearners);
   return jsonObject;
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:14,代码来源:BaseLearnerJsonObjectCreator.java

示例5: getEvalautionMetricJsonArray

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * The utility method to create json object for evaluation metric in the json configuration.
 * 
 * @param evaluationMetricElementArray the list of evaluation metric elements
 * @return the json object of the evaluation metric
 */
public static JsonObject getEvalautionMetricJsonArray(List<EvaluationMetricJsonElement> evaluationMetricElementArray) {
   Gson gson = new GsonBuilder().create();
   JsonElement evaluationMetrics = gson.toJsonTree(evaluationMetricElementArray);
   JsonObject jsonObject = new JsonObject();
   jsonObject.add(EvaluationsKeyValuePairs.EVALUATION_METRIC_ARRAY_IDENTIFIER, evaluationMetrics);
   return jsonObject;
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:14,代码来源:EvaluateAlgorithmsCommand.java

示例6: getEvalautionMetricJsonArray

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * The utility method to create json object for evaluation metric in the json configuration.
 * 
 * @param evaluationMetricElementArray the list of evaluation metric elements
 * @return the json object of the evaluation metric
 */
public static JsonObject getEvalautionMetricJsonArray(List<EvaluationMetricJsonObjectCreator> evaluationMetricElementArray) {
   Gson gson = new GsonBuilder().create();
   JsonElement evaluationMetrics = gson.toJsonTree(evaluationMetricElementArray);
   JsonObject jsonObject = new JsonObject();
   jsonObject.add("evaluation_metrics", evaluationMetrics);
   return jsonObject;
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:14,代码来源:EvaluationMetricJsonObjectCreator.java

示例7: getBaseLearnerJsonArray

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * The utility method to create json object for evaluation metric in the json configuration.
 * 
 * @param baseLearnerObjectArray the list of evaluation metric elements
 * @return the json object of the evaluation metric
 */
public static JsonObject getBaseLearnerJsonArray(List<BaseLearnerJsonObjectCreator> baseLearnerObjectArray) {
   Gson gson = new GsonBuilder().create();
   JsonElement baseLearners = gson.toJsonTree(baseLearnerObjectArray);
   JsonObject jsonObject = new JsonObject();
   jsonObject.add(PARAMETER_BASELEARNER, baseLearners);
   return jsonObject;
}
 
开发者ID:Intelligent-Systems-Group,项目名称:jpl-framework,代码行数:14,代码来源:BaseLearnerJsonObjectCreator.java

示例8: fetchColumnsForMultipleTables

import com.google.gson.Gson; //导入方法依赖的package包/类
@RequestMapping(value = "/fetchColumnsForMultipleTables")
public void fetchColumnsForMultipleTables(HttpServletRequest request, HttpServletResponse response) throws IOException {
	logger.info("Inside fetchColumnsForMultipleTables");
	String jsonColumnsDtl = "";
	List<String> tableNameList = null;
	JsonArray jsonArray = new JsonArray();
	Gson gson = new Gson();
	String tableName = request.getParameter("tableName").trim().equalsIgnoreCase("") ? ""
			: request.getParameter("tableName").trim();
	logger.info("Fetch column for TableName : " + tableName);
	String sourceDatabaseName = request.getParameter("sourceDatabaseName");
	logger.info("Source DB is:" + sourceDatabaseName);
	String sourceDatabaseSchema = request.getParameter("sourceDatabaseSchema");
	logger.info("Source schema is:" + sourceDatabaseSchema);
	if(tableName != null && !tableName.isEmpty()){
		tableNameList = Arrays.asList(tableName.split(","));
	}
	DatabaseDetailsService databaseDetailsService = new DatabaseDetailsServiceImpl();
	Map<String, Object> outPut = databaseDetailsService.fetchColumnsForMultipleTables(sourceDatabaseName,sourceDatabaseSchema, tableNameList);
	if (SyncConstants.SUCCESS.equalsIgnoreCase(String.valueOf(outPut.get("result")))) {
		@SuppressWarnings("unchecked")
		Map<String, OracleColumn> columnsMap = (Map<String, OracleColumn>) outPut.get("output");
		for(Entry<String,OracleColumn> entry : columnsMap.entrySet()){
			JsonObject obj = new JsonObject();
			obj.addProperty("tableName", entry.getKey());
			JsonElement jsonElement = gson.toJsonTree(entry.getValue());
			obj.add("columns", jsonElement);
			jsonArray.add(obj);
		}
	}
	jsonColumnsDtl = jsonArray.toString();
	response.setContentType(SyncConstants.CONTENT_TYPE_JSON);
	response.getWriter().println(jsonColumnsDtl);
	logger.info("Inside fetchColumnsForMultipleTables Completed");
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:36,代码来源:DatabaseDetailsController.java

示例9: serialize

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public JsonElement serialize(ScriptObjectMirror src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context) {
    Gson gson = new Gson();
    
    if (src.isArray()) {
        return gson.toJsonTree(src.values());
    } else {
        return gson.toJsonTree(src);
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:11,代码来源:ScriptObjectMirrorSerializer.java

示例10: getRequests

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * Method of getting all requests from a given current session
 *
 * @param cleanuptype Session type name in Elasticsearch
 * @param sessionID   Session ID
 * @return all of these requests in JSON
 * @throws UnsupportedEncodingException UnsupportedEncodingException
 */
private JsonElement getRequests(String cleanuptype, String sessionID) throws UnsupportedEncodingException {
  SearchResponse response = es.getClient().prepareSearch(props.getProperty("indexName")).setTypes(cleanuptype).setQuery(QueryBuilders.termQuery("SessionID", sessionID)).setSize(100)
      .addSort("Time", SortOrder.ASC).execute().actionGet();

  Gson gson = new Gson();
  List<JsonObject> requestList = new ArrayList<>();
  int seq = 1;
  for (SearchHit hit : response.getHits().getHits()) {
    Map<String, Object> result = hit.getSource();
    String request = (String) result.get("Request");
    String requestUrl = (String) result.get("RequestUrl");
    String time = (String) result.get("Time");
    String logType = (String) result.get("LogType");
    String referer = (String) result.get("Referer");

    JsonObject req = new JsonObject();
    req.addProperty("Time", time);
    req.addProperty("Request", request);
    req.addProperty("RequestURL", requestUrl);
    req.addProperty("LogType", logType);
    req.addProperty("Referer", referer);
    req.addProperty("Seq", seq);
    requestList.add(req);

    seq++;
  }
  return gson.toJsonTree(requestList);
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:37,代码来源:Session.java

示例11: treeToJson

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * TreeToJson: Convert the session tree to Json object
 *
 * @param node node of the session tree
 * @return tree content in Json format
 */
public JsonObject treeToJson(SessionNode node) {
  Gson gson = new Gson();
  JsonObject json = new JsonObject();

  json.addProperty("seq", node.getSeq());
  if ("datasetlist".equals(node.getKey())) {
    json.addProperty("icon", "./resources/images/searching.png");
    json.addProperty("name", node.getRequest());
  } else if ("dataset".equals(node.getKey())) {
    json.addProperty("icon", "./resources/images/viewing.png");
    json.addProperty("name", node.getDatasetId());
  } else if ("ftp".equals(node.getKey())) {
    json.addProperty("icon", "./resources/images/downloading.png");
    json.addProperty("name", node.getRequest());
  } else if ("root".equals(node.getKey())) {
    json.addProperty("name", "");
    json.addProperty("icon", "./resources/images/users.png");
  }

  if (!node.children.isEmpty()) {
    List<JsonObject> jsonChildren = new ArrayList<>();
    for (int i = 0; i < node.children.size(); i++) {
      JsonObject jsonChild = treeToJson(node.children.get(i));
      jsonChildren.add(jsonChild);
    }
    JsonElement jsonElement = gson.toJsonTree(jsonChildren);
    json.add("children", jsonElement);
  }

  return json;
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:38,代码来源:SessionTree.java

示例12: ssearch

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * Method of semantic search to generate JSON string
 *
 * @param index          index name in Elasticsearch
 * @param type           type name in Elasticsearch
 * @param query          regular query string
 * @param queryOperator query mode- query, or, and
 * @param rr             selected ranking method
 * @return search results
 */
public String ssearch(String index, String type, String query, String queryOperator, String rankOption, Ranker rr) {
  List<SResult> li = searchByQuery(index, type, query, queryOperator, rankOption);
  if ("Rank-SVM".equals(rankOption)) {
    li = rr.rank(li);
  }
  Gson gson = new Gson();
  List<JsonObject> fileList = new ArrayList<>();

  for (int i = 0; i < li.size(); i++) {
    JsonObject file = new JsonObject();
    file.addProperty("Short Name", (String) SResult.get(li.get(i), "shortName"));
    file.addProperty("Long Name", (String) SResult.get(li.get(i), "longName"));
    file.addProperty("Topic", (String) SResult.get(li.get(i), "topic"));
    file.addProperty("Description", (String) SResult.get(li.get(i), "description"));
    file.addProperty("Release Date", (String) SResult.get(li.get(i), "relase_date"));
    fileList.add(file);

    file.addProperty("Start/End Date", (String) SResult.get(li.get(i), "startDate") + " - " + (String) SResult.get(li.get(i), "endDate"));
    file.addProperty("Processing Level", (String) SResult.get(li.get(i), "processingLevel"));

    file.addProperty("Sensor", (String) SResult.get(li.get(i), "sensors"));
  }
  JsonElement fileListElement = gson.toJsonTree(fileList);

  JsonObject pDResults = new JsonObject();
  pDResults.add("PDResults", fileListElement);
  return pDResults.toString();
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:39,代码来源:Searcher.java

示例13: testSerializationFail

import com.google.gson.Gson; //导入方法依赖的package包/类
@Test(expectedExceptions = JsonParseException.class)
public void testSerializationFail() {
    Gson gson = getGSON(getFactory(t -> "foo", emptyList(), emptyList()));
    // Not registered
    SubTypeC typeC = new SubTypeC();
    typeC.foo = 1;
    typeC.bar = "t1";
    typeC.norf = true;

    gson.toJsonTree(typeC, new TypeToken<Base>() { }.getType());
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:12,代码来源:FieldTypeAdapterFactoryTest.java

示例14: serialize

import com.google.gson.Gson; //导入方法依赖的package包/类
@Override
public JsonElement serialize(RelationshipAction relationshipAction, Type type, JsonSerializationContext jsonSerializationContext) {
	Gson gson = new Gson();
	return gson.toJsonTree(relationshipAction.getValue());
}
 
开发者ID:zralock,项目名称:CTUConference,代码行数:6,代码来源:RelationshipActionTypeSerializer.java

示例15: getJsonObject

import com.google.gson.Gson; //导入方法依赖的package包/类
/**
 * @return Encoded JsonObject representation of PublicKeyCredentialEntity
 */
public JsonObject getJsonObject() {
  Gson gson = new Gson();
  return (JsonObject) gson.toJsonTree(this);
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:8,代码来源:PublicKeyCredentialEntity.java


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