本文整理汇总了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();
}
示例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.
}
示例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();
}
示例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();
}
示例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));
}
示例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());
}
}
示例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());
}