本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerator.writeFieldName方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeFieldName方法的具体用法?Java JsonGenerator.writeFieldName怎么用?Java JsonGenerator.writeFieldName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeFieldName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(ObfuscationLinkState oLinkState, JsonGenerator jGen,
SerializerProvider arg2) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("src", oLinkState.getLink().getSrc().toString());
jGen.writeStringField("dst", oLinkState.getLink().getDst().toString());
jGen.writeNumberField("srcPort", oLinkState.getLink().getSrcPort().getPortNumber());
jGen.writeNumberField("dstPort", oLinkState.getLink().getDstPort().getPortNumber());
jGen.writeFieldName("masks");
jGen.writeStartArray();
for (long dst: oLinkState.getInstalledMasks().keySet()) {
jGen.writeStartObject();
//jGen.writeStringField("dst", dst.toString());
jGen.writeNumberField("observed_entropy", oLinkState.getObservedEntropy(dst));
jGen.writeNumberField("unicity_distance", oLinkState.getUnicityDistance(dst));
jGen.writeNumberField("flows", oLinkState.getNumberOfMaskUsages(dst));
jGen.writeEndObject();
}
jGen.writeEndArray();
jGen.writeEndObject();
}
示例2: serializeAttributes
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void serializeAttributes(Map<Object, Object> attributes, JsonGenerator jGen)
throws IOException, JsonProcessingException {
if ( null == attributes)
jGen.writeStringField("attributes","null");
else{
jGen.writeFieldName("attributes");
jGen.writeStartObject();
for (Map.Entry<Object, Object> entry : attributes.entrySet()) {
if( entry.getValue() instanceof EnumSet<?>){
jGen.writeFieldName(entry.getKey().toString());
jGen.writeStartArray();
//Maybe need to check other type.
for(OFFlowWildcards wildcard : (EnumSet<OFFlowWildcards>)entry.getValue()){
jGen.writeString(wildcard.toString());
}
jGen.writeEndArray();
}
else
jGen.writeStringField(entry.getKey().toString(),entry.getValue().toString());
}
jGen.writeEndObject();
}
}
示例3: _testFailOnWritingFieldNameInRoot
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
private void _testFailOnWritingFieldNameInRoot(JsonFactory f, boolean useReader) throws Exception
{
JsonGenerator gen;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
if (useReader) {
gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
} else {
gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
}
try {
gen.writeFieldName("a");
gen.flush();
String json = bout.toString("UTF-8");
fail("Should not have let "+gen.getClass().getName()+".writeFieldName() be used in root context: output = "+json);
} catch (JsonProcessingException e) {
verifyException(e, "can not write a field name");
}
gen.close();
}
示例4: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(BeakerCodeCell value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException, JsonProcessingException {
synchronized (value) {
jgen.writeStartObject();
jgen.writeStringField("type", "BeakerCodeCell");
jgen.writeStringField("execution_count", value.executionCount);
jgen.writeStringField("cell_type", value.cellType);
jgen.writeFieldName("outputs");
if (!getObjectSerializer().writeObject(value.outputs, jgen, true))
jgen.writeString(value.outputs.toString());
jgen.writeFieldName("metadata");
if (!getObjectSerializer().writeObject(value.metadata, jgen, true))
jgen.writeString(value.metadata.toString());
jgen.writeStringField("source", value.source);
jgen.writeEndObject();
}
}
示例5: serializeMeterFeaturesReply
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
/***
* Serializes Meter Feature Reply
* @author Naveen
* @param meterFeaturesReplies
* @param jGen
* @throws IOException
* @throws JsonProcessingException
*/
public static void serializeMeterFeaturesReply(List<OFMeterFeaturesStatsReply> meterFeaturesReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{
OFMeterFeaturesStatsReply meterFeaturesReply = meterFeaturesReplies.get(0);
jGen.writeStringField("version", meterFeaturesReply.getVersion().toString()); //return the enum name
OFMeterFeatures meterFeatures = meterFeaturesReply.getFeatures();
jGen.writeFieldName("meterFeatures");
jGen.writeStartObject();
jGen.writeNumberField("maxGroupsAll",meterFeatures.getMaxMeter());
jGen.writeNumberField("maxGroupsSelect",meterFeatures.getBandTypes());
jGen.writeNumberField("capabilities",meterFeatures.getCapabilities());
jGen.writeNumberField("maxGroupsIndirect",meterFeatures.getMaxBands());
jGen.writeNumberField("maxGroupsFf",meterFeatures.getMaxColor());
jGen.writeEndObject();//end of group Feature
}
示例6: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(OFFlowModMap fmm, JsonGenerator jGen, SerializerProvider serializer)
throws IOException, JsonProcessingException {
jGen.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true); // IMHO this just looks nicer and is easier to read if everything is quoted
if (fmm == null) {
jGen.writeStartObject();
jGen.writeString("No flows have been added to the Static Flow Pusher.");
jGen.writeEndObject();
return;
}
Map<String, Map<String, OFFlowMod>> theMap = fmm.getMap();
jGen.writeStartObject();
if (theMap.keySet() != null) {
for (String dpid : theMap.keySet()) {
if (theMap.get(dpid) != null) {
jGen.writeArrayFieldStart(dpid);
for (String name : theMap.get(dpid).keySet()) {
jGen.writeStartObject();
jGen.writeFieldName(name);
OFFlowModSerializer.serializeFlowMod(jGen, theMap.get(dpid).get(name));
jGen.writeEndObject();
}
jGen.writeEndArray();
}
}
}
jGen.writeEndObject();
}
示例7: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(NonPrivateFieldsFieldDetectionPolicyModel object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException {
if (writeStartAndEnd) {
jsonGenerator.writeStartObject();
}
if (object.annotatedString != null) {
jsonGenerator.writeStringField("annotated_string", object.annotatedString);
}
jsonGenerator.writeNumberField("intToIgnoreForParse", object.intToIgnoreForParse);
final List<String> lslocalnonAnnotatedList = object.nonAnnotatedList;
if (lslocalnonAnnotatedList != null) {
jsonGenerator.writeFieldName("nonAnnotatedList");
jsonGenerator.writeStartArray();
for (String element1 : lslocalnonAnnotatedList) {
if (element1 != null) {
jsonGenerator.writeString(element1);
}
}
jsonGenerator.writeEndArray();
}
if (object.nonAnnotatedString != null) {
jsonGenerator.writeStringField("nonAnnotatedString", object.nonAnnotatedString);
}
jsonGenerator.writeNumberField("staticIntToInclude", object.staticIntToInclude);
jsonGenerator.writeNumberField("transientIntToInclude", object.transientIntToInclude);
if (writeStartAndEnd) {
jsonGenerator.writeEndObject();
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:NonPrivateFieldsFieldDetectionPolicyModel$$JsonObjectMapper.java
示例8: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(NonPrivateFieldsAndAccessorsFieldDetectionPolicyModel object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException {
if (writeStartAndEnd) {
jsonGenerator.writeStartObject();
}
if (object.annotatedString != null) {
jsonGenerator.writeStringField("annotated_string", object.annotatedString);
}
jsonGenerator.writeNumberField("intToIgnoreForParse", object.intToIgnoreForParse);
final List<String> lslocalnonAnnotatedList = object.nonAnnotatedList;
if (lslocalnonAnnotatedList != null) {
jsonGenerator.writeFieldName("nonAnnotatedList");
jsonGenerator.writeStartArray();
for (String element1 : lslocalnonAnnotatedList) {
if (element1 != null) {
jsonGenerator.writeString(element1);
}
}
jsonGenerator.writeEndArray();
}
jsonGenerator.writeNumberField("nonAnnotatedPrivateInt", object.getNonAnnotatedPrivateInt());
if (object.nonAnnotatedString != null) {
jsonGenerator.writeStringField("nonAnnotatedString", object.nonAnnotatedString);
}
jsonGenerator.writeNumberField("privateStaticIntToInclude", object.getPrivateStaticIntToInclude());
jsonGenerator.writeNumberField("privateTransientIntToInclude", object.getPrivateTransientIntToInclude());
jsonGenerator.writeNumberField("staticIntToInclude", object.staticIntToInclude);
jsonGenerator.writeNumberField("transientIntToInclude", object.transientIntToInclude);
if (writeStartAndEnd) {
jsonGenerator.writeEndObject();
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:NonPrivateFieldsAndAccessorsFieldDetectionPolicyModel$$JsonObjectMapper.java
示例9: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(SimpleWrapperModel object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException {
if (writeStartAndEnd) {
jsonGenerator.writeStartObject();
}
if (object.wrappedObject != null) {
jsonGenerator.writeFieldName("wrappedObject");
COM_BLUELINELABS_LOGANSQUARE_PROCESSOR_SIMPLEWRAPPERMODEL_WRAPPEDCLASS__JSONOBJECTMAPPER.serialize(object.wrappedObject, jsonGenerator, true);
}
if (writeStartAndEnd) {
jsonGenerator.writeEndObject();
}
}
示例10: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeStringField("op", op);
gen.writeStringField("path", path.toString());
gen.writeFieldName("oldValue");
gen.writeTree(oldValue);
gen.writeFieldName("value");
gen.writeTree(newValue);
gen.writeEndObject();
}
示例11: serializePortReply
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public static void serializePortReply(List<OFPortStatsReply> portReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{
OFPortStatsReply portReply = portReplies.get(0); // we will get only one PortReply and it will contains many OFPortStatsEntry ?
jGen.writeStringField("version", portReply.getVersion().toString()); //return the enum name
jGen.writeFieldName("port");
jGen.writeStartArray();
for(OFPortStatsEntry entry : portReply.getEntries()) {
jGen.writeStartObject();
jGen.writeStringField("portNumber",entry.getPortNo().toString());
jGen.writeNumberField("receivePackets", entry.getRxPackets().getValue());
jGen.writeNumberField("transmitPackets", entry.getTxPackets().getValue());
jGen.writeNumberField("receiveBytes", entry.getRxBytes().getValue());
jGen.writeNumberField("transmitBytes", entry.getTxBytes().getValue());
jGen.writeNumberField("receiveDropped", entry.getRxDropped().getValue());
jGen.writeNumberField("transmitDropped", entry.getTxDropped().getValue());
jGen.writeNumberField("receiveErrors", entry.getRxErrors().getValue());
jGen.writeNumberField("transmitErrors", entry.getTxErrors().getValue());
jGen.writeNumberField("receiveFrameErrors", entry.getRxFrameErr().getValue());
jGen.writeNumberField("receiveOverrunErrors", entry.getRxOverErr().getValue());
jGen.writeNumberField("receiveCRCErrors", entry.getRxCrcErr().getValue());
jGen.writeNumberField("collisions", entry.getCollisions().getValue());
if (OFVersion.OF_13 == entry.getVersion()) {
jGen.writeNumberField("durationSec", entry.getDurationSec());
jGen.writeNumberField("durationNsec", entry.getDurationNsec());
}
jGen.writeEndObject();
}
jGen.writeEndArray();
}
示例12: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(I18NStrings value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
JsonProcessingException
{
jgen.writeStartObject();
Map<String, String> strings = value.getStrings();
for( Entry<String, String> string : strings.entrySet() )
{
jgen.writeFieldName(string.getKey());
jgen.writeString(string.getValue());
}
jgen.writeEndObject();
}
示例13: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(CategoryEntity value, JsonGenerator gen, SerializerProvider provider) throws IOException {
if (null == value) {
throw new JsonGenerationException("Could not serialize object to json, input object to serialize is null");
}
StringWriter writer = new StringWriter();
mapper.writeValue(writer, value);
gen.writeFieldName(writer.toString());
}
示例14: processToken
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
private JsonToken processToken(JsonToken curToken, JsonParser parser, JsonGenerator jgen)
throws IOException {
if (curToken.isStructEnd()) {
// this is our escape and base case.
return curToken;
}
if (curToken.isStructStart()) {
processStructStart(curToken, jgen);
JsonToken token = processToken(parser.nextToken(), parser, jgen);
while (!token.isStructEnd()) {
token = processToken(token, parser, jgen);
}
processStructEnd(token, jgen);
return parser.nextToken();
}
if (curToken.id() == JsonTokenId.ID_FIELD_NAME) {
String currentName = parser.getCurrentName();
if (isFiltered && filters.containsKey(parser.getCurrentName())) {
jgen.writeFieldName(currentName);
// perform filtering.
return filters.get(parser.getCurrentName()).processToken(parser.nextToken(), parser, jgen);
} else if (!isFiltered) {
jgen.writeFieldName(currentName);
return processToken(parser.nextToken(), parser, jgen);
} else {
parser.nextToken();
parser.skipChildren();
return processToken(parser.nextToken(), parser, jgen);
}
} else if (curToken.isScalarValue()) {
processValue(curToken, parser, jgen);
return parser.nextToken();
} else {
LOGGER.error(
"Unable to process the token {} with name {}.", curToken, parser.getCurrentName());
throw new RuntimeException(
"Unable to process the token " + curToken + " with name" + parser.getCurrentName());
}
}
示例15: serializeMeterReply
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
/***
* Serializes the Meter Statistics Reply
* @author Naveen
* @param meterReplies
* @param jGen
* @throws IOException
* @throws JsonProcessingException
*/
public static void serializeMeterReply(List<OFMeterStatsReply> meterReplies, JsonGenerator jGen) throws IOException, JsonProcessingException{
OFMeterStatsReply meterReply = meterReplies.get(0); // we will get only one meterReply and it will contains many OFMeterStatsEntry ?
jGen.writeStringField("version", meterReply.getVersion().toString()); //return the enum name
jGen.writeFieldName("meter");
jGen.writeStartArray();
for(OFMeterStats entry : meterReply.getEntries()) {
jGen.writeStartObject();
jGen.writeNumberField("meterId",entry.getMeterId());
jGen.writeNumberField("flowCount", entry.getFlowCount());
jGen.writeNumberField("packetInCount", entry.getPacketInCount().getValue());
jGen.writeNumberField("byteInCount", entry.getByteInCount().getValue());
jGen.writeFieldName("meterBandStats");
jGen.writeStartArray();
for(OFMeterBandStats bandStats : entry.getBandStats()) {
jGen.writeStartObject();
jGen.writeNumberField("packetBandCount", bandStats.getPacketBandCount().getValue());
jGen.writeNumberField("byteBandCount", bandStats.getByteBandCount().getValue());
jGen.writeEndObject();
}//End of for loop - bandStats
jGen.writeEndArray();
jGen.writeNumberField("durationSec", entry.getDurationSec());
jGen.writeNumberField("durationNsec", entry.getDurationNsec());
jGen.writeEndObject();
}//End of for loop - MeterStats
jGen.writeEndArray();
}