當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonGenerator.writeObjectField方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.JsonGenerator.writeObjectField方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.writeObjectField方法的具體用法?Java JsonGenerator.writeObjectField怎麽用?Java JsonGenerator.writeObjectField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.writeObjectField方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialize

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Map<String, Object> fields, JsonGenerator jgen,
		SerializerProvider provider) throws IOException,
		JsonProcessingException {
	jgen.writeStartObject();
	for (Entry<String, Object> entry : fields.entrySet()) {
		Object objectValue = entry.getValue();
		if (objectValue instanceof Date) {
			Date date = (Date) objectValue;
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
			simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
			String formattedDate = simpleDateFormat.format(date);
			jgen.writeObjectField(entry.getKey().toString(), formattedDate);
		} else {
			jgen.writeObjectField(entry.getKey().toString(), objectValue);
		}
	}
	jgen.writeEndObject();
}
 
開發者ID:cheetah100,項目名稱:gravity,代碼行數:20,代碼來源:MapJsonSerializer.java

示例2: write

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * Used to write the state of the ClusterNode instance to disk, when we are
 * persisting the state of the NodeManager
 * @param jsonGenerator The JsonGenerator instance being used to write JSON
 *                      to disk
 * @throws IOException
 */
public void write(JsonGenerator jsonGenerator) throws IOException {
  jsonGenerator.writeStartObject();

  // clusterNodeInfo begins
  jsonGenerator.writeFieldName("clusterNodeInfo");
  jsonGenerator.writeStartObject();
  jsonGenerator.writeStringField("name", clusterNodeInfo.name);
  jsonGenerator.writeObjectField("address", clusterNodeInfo.address);
  jsonGenerator.writeObjectField("total", clusterNodeInfo.total);
  jsonGenerator.writeObjectField("free", clusterNodeInfo.free);
  jsonGenerator.writeObjectField("resourceInfos",
    clusterNodeInfo.resourceInfos);
  jsonGenerator.writeEndObject();
  // clusterNodeInfo ends

  // grants begins
  jsonGenerator.writeFieldName("grants");
  jsonGenerator.writeStartObject();
  for (Map.Entry<GrantId, ResourceRequestInfo> entry : grants.entrySet()) {
    jsonGenerator.writeFieldName(entry.getKey().unique);
    jsonGenerator.writeStartObject();
    jsonGenerator.writeFieldName("grantId");
    entry.getKey().write(jsonGenerator);
    jsonGenerator.writeFieldName("grant");
    entry.getValue().write(jsonGenerator);
    jsonGenerator.writeEndObject();
  }
  jsonGenerator.writeEndObject();
  // grants ends

  jsonGenerator.writeEndObject();
  // We skip the hostNode and lastHeartbeatTime as they need not be persisted.
  // resourceTypeToMaxCpu and resourceTypeToStatsMap can be rebuilt using the
  // conf and the grants respectively.
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:43,代碼來源:ClusterNode.java

示例3: write

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * Used to write the state of the SessionNotificationCtx instance to disk,
 * when we are persisting the state of the ClusterManager
 * @param jsonGenerator The JsonGenerator instance being used to write JSON
 *                      to disk
 * @throws IOException
 */
public void write(JsonGenerator jsonGenerator) throws IOException {
  jsonGenerator.writeStartObject();

  jsonGenerator.writeStringField("handle", handle);

  jsonGenerator.writeStringField("host", host);

  jsonGenerator.writeNumberField("port", port);

  jsonGenerator.writeNumberField("numPendingCalls", pendingCalls.size());

  jsonGenerator.writeFieldName("pendingCalls");
  jsonGenerator.writeStartArray();
  for (TBase call : pendingCalls) {
    jsonGenerator.writeStartObject();

    // TBase is an abstract class. While reading back, we want to know
    // what kind of object we actually wrote. Jackson does provide two methods
    // to do it automatically, but one of them adds types at a lot of places
    // where we don't need it, and hence our parsing would be required to be
    // changed. The other required adding an annotation to the TBase class,
    // which we can't do, since it is auto-generated by Thrift.
    String callType = call.getClass().getName();
    jsonGenerator.writeStringField("callType", callType);

    jsonGenerator.writeObjectField("call", call);

    jsonGenerator.writeEndObject();
  }
  jsonGenerator.writeEndArray();

  jsonGenerator.writeEndObject();
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:41,代碼來源:SessionNotificationCtx.java

示例4: write

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * This method writes the ResourceRequestInfo instance to disk
 * @param jsonGenerator The JsonGenerator instance being used to write the
 *                      JSON to disk
 * @throws IOException
 */
public void write(JsonGenerator jsonGenerator) throws IOException {
  // We neither need the list of RequestedNodes, nodes, nor excludedHosts,
  // because we can reconstruct them from the request object
  jsonGenerator.writeStartObject();
  jsonGenerator.writeObjectField("request", request);
  jsonGenerator.writeEndObject();
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:14,代碼來源:ResourceRequestInfo.java

示例5: writeLinks

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private void writeLinks(final CollectionPage<Object> value, final JsonGenerator jgen) throws IOException {
    jgen.writeObjectField("links", getLinks(value));
}
 
開發者ID:JohnDeere,項目名稱:MyJohnDeereAPI-OAuth-Java-Client,代碼行數:4,代碼來源:CollectionPageSerializer.java

示例6: writeJSON

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
protected void writeJSON(JsonGenerator gen) throws IOException {
    for (Map.Entry<String, String> entry : entrySet()) {
        gen.writeObjectField(entry.getKey(), entry.getValue());
    }
}
 
開發者ID:adohe,項目名稱:Bottlenose,代碼行數:6,代碼來源:PropertyMap.java

示例7: writeJson

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
void writeJson(JsonGenerator gen) throws IOException {
    for (Map.Entry<String, String> e : entrySet())
        gen.writeObjectField(e.getKey(), e.getValue());
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:5,代碼來源:PropertyMap.java


注:本文中的org.codehaus.jackson.JsonGenerator.writeObjectField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。