当前位置: 首页>>代码示例>>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;未经允许,请勿转载。