本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerator.writeObjectField方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeObjectField方法的具体用法?Java JsonGenerator.writeObjectField怎么用?Java JsonGenerator.writeObjectField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeObjectField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJSONFromFields
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
private String buildJSONFromFields(Collection<SearchHitField> values) {
JsonFactory nodeFactory = new JsonFactory();
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
generator.writeStartObject();
for (SearchHitField value : values) {
if (value.getValues().size() > 1) {
generator.writeArrayFieldStart(value.getName());
for (Object val : value.getValues()) {
generator.writeObject(val);
}
generator.writeEndArray();
} else {
generator.writeObjectField(value.getName(), value.getValue());
}
}
generator.writeEndObject();
generator.flush();
return new String(stream.toByteArray(), Charset.forName("UTF-8"));
} catch (IOException e) {
return null;
}
}
示例2: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(
QueryOptions queryOptions, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject(queryOptions);
jsonGenerator.writeObjectField("consistency", toConsistencyString(queryOptions.consistency));
jsonGenerator.writeObjectField("positional_values", queryOptions.positionalValues);
jsonGenerator.writeObjectField("named_values", queryOptions.namedValues);
jsonGenerator.writeObjectField("skip_metadata", queryOptions.skipMetadata);
jsonGenerator.writeObjectField("page_size", queryOptions.pageSize);
jsonGenerator.writeObjectField("paging_state", queryOptions.pagingState);
jsonGenerator.writeObjectField(
"serial_consistency", toConsistencyString(queryOptions.serialConsistency));
jsonGenerator.writeObjectField("default_timestamp", queryOptions.defaultTimestamp);
jsonGenerator.writeObjectField("keyspace", queryOptions.keyspace);
jsonGenerator.writeEndObject();
}
示例3: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(T xyGraphics, JsonGenerator jgen, SerializerProvider sp)
throws IOException, JsonProcessingException {
super.serialize(xyGraphics, jgen, sp);
boolean isNanoPlot = NanoPlot.class.equals(xyGraphics.getPlotType());
jgen.writeObjectField("x", isNanoPlot ? processLargeNumbers(xyGraphics.getX()) : xyGraphics.getX());
jgen.writeObjectField("y", xyGraphics.getY());
jgen.writeObjectField(DISPLAY_NAME, xyGraphics.getDisplayName());
if (xyGraphics.getLodFilter() != null){
jgen.writeObjectField("lod_filter", xyGraphics.getLodFilter().getText());
}
List<String> toolTips = xyGraphics.getToolTips();
if (toolTips != null) {
jgen.writeObjectField("tooltips", toolTips);
}
}
示例4: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Line line, JsonGenerator jgen, SerializerProvider sp)
throws IOException, JsonProcessingException {
jgen.writeStartObject();
super.serialize(line, jgen, sp);
if (line.getLodFilter() != null)
jgen.writeObjectField("lod_filter", line.getLodFilter().getText());
if (line.getColor() instanceof Color) {
jgen.writeObjectField("color", line.getColor());
}
if (line.getWidth() != null) {
jgen.writeObjectField("width", line.getWidth());
}
if (line.getStyle() != null) {
jgen.writeObjectField("style", line.getStyle().toString());
}
if (line.getInterpolation() != null) {
jgen.writeObjectField("interpolation", line.getInterpolation());
}
jgen.writeEndObject();
}
示例5: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(JsonMeter jsonMeter,
JsonGenerator json,
SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField("name", jsonMeter.name());
json.writeObjectField(timestampFieldname, jsonMeter.timestampAsDate());
Meter meter = jsonMeter.value();
json.writeNumberField("count", meter.getCount());
json.writeNumberField("m1_rate", meter.getOneMinuteRate() * rateFactor);
json.writeNumberField("m5_rate", meter.getFiveMinuteRate() * rateFactor);
json.writeNumberField("m15_rate", meter.getFifteenMinuteRate() * rateFactor);
json.writeNumberField("mean_rate", meter.getMeanRate() * rateFactor);
json.writeStringField("units", rateUnit);
addOneOpsMetadata(json);
json.writeEndObject();
}
示例6: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(final T component,
final JsonGenerator jgen,
final SerializerProvider serializerProvider) throws IOException {
jgen.writeStartObject();
jgen.writeObjectField("type", component.getClass().getSimpleName());
if (component.getLabel() != null) {
jgen.writeStringField("label", component.getLabel());
}
jgen.writeBooleanField("enabled", component.isEnabled());
if (component.getValue() != null) {
jgen.writeObjectField("value", component.getValue());
}
writeSubclassFields(jgen, component);
jgen.writeEndObject();
}
示例7: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(ValueStringFormat value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException, JsonProcessingException {
synchronized (value) {
jgen.writeStartObject();
jgen.writeObjectField("type", "value");
jgen.writeObjectField("values", value.getValues());
jgen.writeEndObject();
}
}
示例8: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Fact value, JsonGenerator g, SerializerProvider provider) throws IOException {
g.writeStartObject();
g.writeObjectField("s", value.getSubject());
g.writeObjectField("p", value.getPredicate());
g.writeObjectField("o", value.getObject());
g.writeEndObject();
}
示例9: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(BufferedImage v, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
synchronized(v) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(v, "png", baos);
byte [] data = baos.toByteArray();
jgen.writeStartObject();
jgen.writeStringField("type", "ImageIcon");
jgen.writeObjectField("imageData", data);
jgen.writeNumberField("width", v.getWidth());
jgen.writeNumberField("height", v.getHeight());
jgen.writeEndObject();
}
}
示例10: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void serialize(TreeMapNode treeMapNode,
JsonGenerator jgen,
SerializerProvider provider) throws
IOException,
JsonProcessingException {
jgen.writeStartObject();
jgen.writeObjectField("type", treeMapNode.getClass().getSimpleName());
jgen.writeObjectField("weight", treeMapNode.getWeight());
if (treeMapNode.getValue() != null) {
jgen.writeObjectField("doubleValue", treeMapNode.getDoubleValue());
jgen.writeObjectField("labelValue", treeMapNode.getLabelValue());
Object userObject = treeMapNode.getUserObject();
Map<String, Object> values = (Map<String, Object>) userObject;
jgen.writeObjectField("label", values.get("label"));
jgen.writeObjectField("color", values.get("color"));
jgen.writeObjectField("tooltip", values.get("tooltip"));
}
if (treeMapNode.getChildren() != null)
jgen.writeObjectField("children", treeMapNode.getChildren());
jgen.writeEndObject();
}
示例11: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Object value, JsonGenerator gen,
SerializerProvider serializers) throws IOException, JsonProcessingException {
gen.writeStartObject();
ProtobufGenerator protobufGenerator = (ProtobufGenerator) gen;
ProtobufField field = protobufGenerator.getSchema().getRootType().firstField();
gen.writeObjectField(field.name, value);
gen.writeEndObject();
}
示例12: writeObject
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public boolean writeObject(Object obj, JsonGenerator jgen, boolean expand) throws JsonProcessingException, IOException {
logger.debug("primitive type map");
List<String> columns = new ArrayList<String>();
columns.add("Key");
columns.add("Value");
List<List<?>> values = new ArrayList<List<?>>();
Map<?, ?> m = scala.collection.JavaConversions.mapAsJavaMap((scala.collection.Map<?, ?>) obj);
Set<?> keys = m.keySet();
for(Object key : keys) {
Object val = m.get(key);
List<Object> l = new ArrayList<Object>();
l.add(key.toString());
l.add(val);
values.add(l);
}
jgen.writeStartObject();
jgen.writeObjectField("type", "TableDisplay");
jgen.writeObjectField("columnNames", columns);
jgen.writeObjectField("values", values);
jgen.writeObjectField("subtype", TableDisplay.DICTIONARY_SUBTYPE);
jgen.writeEndObject();
return true;
}
示例13: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(BaseOperation operation, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeStartArray();
jgen.writeString(operation.getType().getCaption().toLowerCase());
jgen.writeStartObject();
if (operation instanceof VoteDto) {
VoteDto vote = (VoteDto) operation;
jgen.writeObjectField(authorField, vote.getAuthor());
jgen.writeObjectField(permlinkField, vote.getPermlink());
jgen.writeObjectField(voterField, vote.getVoter());
jgen.writeObjectField(weightField, vote.getWeight());
} else if (operation instanceof CommentDto) {
CommentDto comment = (CommentDto) operation;
jgen.writeObjectField(parentAuthorField, comment.getParentAuthor());
jgen.writeObjectField(parentPermlinkField, comment.getParentPermlink());
jgen.writeObjectField(authorField, comment.getAuthor());
jgen.writeObjectField(permlinkField, comment.getPermlink());
jgen.writeObjectField(titleField, comment.getTitle());
jgen.writeObjectField(bodyField, comment.getBody());
jgen.writeObjectField(jsonMetadataField, comment.getJsonMetadata());
} else if (operation instanceof TransferDto) {
TransferDto transfer = (TransferDto) operation;
jgen.writeObjectField(parentFromField, transfer.getFrom());
jgen.writeObjectField(parentToField, transfer.getTo());
jgen.writeObjectField(parentAmountField, transfer.getAmount());
jgen.writeObjectField(parentMemoField, transfer.getMemo());
}
jgen.writeEndObject();
jgen.writeEndArray();
}
示例14: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(InstanceEntity value, JsonGenerator g, SerializerProvider provider) throws IOException {
g.writeStartObject();
g.writeStringField("id", value.getId());
g.writeStringField("value", value.getValue());
if (value.getOtherValues() != null && !value.getOtherValues().isEmpty()) {
g.writeObjectField("otherValues", value.getOtherValues());
}
g.writeEndObject();
}
示例15: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Point value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (value == null || value.getCoordinate() == null) {
provider.defaultSerializeNull(jgen);
} else {
jgen.writeStartObject();
jgen.writeObjectField("x", value.getX());
jgen.writeObjectField("y", value.getY());
jgen.writeEndObject();
}
}