当前位置: 首页>>代码示例>>Java>>正文


Java JsonGenerator.writeEndArray方法代码示例

本文整理汇总了Java中org.codehaus.jackson.JsonGenerator.writeEndArray方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeEndArray方法的具体用法?Java JsonGenerator.writeEndArray怎么用?Java JsonGenerator.writeEndArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.jackson.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.writeEndArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeJsonFields

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Writes named schema in JSON format
 *
 * @param gen      JSON generator
 * @param names    list of named schemas already written
 * @param encSpace enclosing namespace of the schema
 */
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names, String encSpace) throws IOException {
    _schemaName.writeJson(gen, names);

    if (_doc != null && !_doc.isEmpty()) {
        gen.writeFieldName("doc");
        gen.writeString(_doc);
    }

    if (_aliases != null) {
        gen.writeFieldName("aliases");
        gen.writeStartArray();
        for (SchemaName name : _aliases) {
            String fullname = name.getSpace() != null ? name.getSpace() + "." + name.getName() : name.getName();
            gen.writeString(fullname);
        }
        gen.writeEndArray();
    }
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:27,代码来源:NamedSchema.java

示例2: dumpConfiguration

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value",
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      dumpGenerator.writeStringField("resource",
                                     config.updatingResource.get(item.getKey()));
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:37,代码来源:Configuration.java

示例3: writeObject

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:JMXJsonServlet.java

示例4: toJson

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Build a JSON entry from the parameters. This is public for testing.
 *
 * @param writer destination
 * @param loggerName logger name
 * @param timeStamp time_t value
 * @param level level string
 * @param threadName name of the thread
 * @param message rendered message
 * @param ti nullable thrown information
 * @return the writer
 * @throws IOException on any problem
 */
public Writer toJson(final Writer writer,
                     final String loggerName,
                     final long timeStamp,
                     final String level,
                     final String threadName,
                     final String message,
                     final ThrowableInformation ti) throws IOException {
  JsonGenerator json = factory.createJsonGenerator(writer);
  json.writeStartObject();
  json.writeStringField(NAME, loggerName);
  json.writeNumberField(TIME, timeStamp);
  Date date = new Date(timeStamp);
  json.writeStringField(DATE, dateFormat.format(date));
  json.writeStringField(LEVEL, level);
  json.writeStringField(THREAD, threadName);
  json.writeStringField(MESSAGE, message);
  if (ti != null) {
    //there is some throwable info, but if the log event has been sent over the wire,
    //there may not be a throwable inside it, just a summary.
    Throwable thrown = ti.getThrowable();
    String eclass = (thrown != null) ?
        thrown.getClass().getName()
        : "";
    json.writeStringField(EXCEPTION_CLASS, eclass);
    String[] stackTrace = ti.getThrowableStrRep();
    json.writeArrayFieldStart(STACK);
    for (String row : stackTrace) {
      json.writeString(row);
    }
    json.writeEndArray();
  }
  json.writeEndObject();
  json.flush();
  json.close();
  return writer;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:50,代码来源:Log4Json.java

示例5: dumpConfiguration

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be 
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] } 
 *  It does not output the parameters of the configuration object which is 
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration config,
    Writer out) throws IOException {
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("properties");
  dumpGenerator.writeStartArray();
  dumpGenerator.flush();
  synchronized (config) {
    for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
      dumpGenerator.writeStartObject();
      dumpGenerator.writeStringField("key", (String) item.getKey());
      dumpGenerator.writeStringField("value", 
                                     config.get((String) item.getKey()));
      dumpGenerator.writeBooleanField("isFinal",
                                      config.finalParameters.contains(item.getKey()));
      String[] resources = config.updatingResource.get(item.getKey());
      String resource = UNKNOWN_RESOURCE;
      if(resources != null && resources.length > 0) {
        resource = resources[0];
      }
      dumpGenerator.writeStringField("resource", resource);
      dumpGenerator.writeEndObject();
    }
  }
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:Configuration.java

示例6: dumpConfiguration

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/***
 * Dumps the configuration of hierarchy of queues with 
 * the xml file path given. It is to be used directly ONLY FOR TESTING.
 * @param out the writer object to which dump is written to.
 * @param configFile the filename of xml file
 * @throws IOException
 */
static void dumpConfiguration(Writer out, String configFile,
    Configuration conf) throws IOException {
  if (conf != null && conf.get(DeprecatedQueueConfigurationParser.
      MAPRED_QUEUE_NAMES_KEY) != null) {
    return;
  }
  
  JsonFactory dumpFactory = new JsonFactory();
  JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
  QueueConfigurationParser parser;
  boolean aclsEnabled = false;
  if (conf != null) {
    aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false);
  }
  if (configFile != null && !"".equals(configFile)) {
    parser = new QueueConfigurationParser(configFile, aclsEnabled);
  }
  else {
    parser = getQueueConfigurationParser(null, false, aclsEnabled);
  }
  dumpGenerator.writeStartObject();
  dumpGenerator.writeFieldName("queues");
  dumpGenerator.writeStartArray();
  dumpConfiguration(dumpGenerator,parser.getRoot().getChildren());
  dumpGenerator.writeEndArray();
  dumpGenerator.writeEndObject();
  dumpGenerator.flush();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:36,代码来源:QueueManager.java

示例7: writeJson

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Writes the Field class in JSON format
 *
 * @param node
 * @param names
 * @param encSpace
 */
protected void writeJson(JsonGenerator node, SchemaNames names, String encSpace)
        throws IOException {
    node.writeStartObject();
    JsonHelper.writeIfNotNullOrEmpty(node, "name", _name);
    JsonHelper.writeIfNotNullOrEmpty(node, "doc", _doc);

    if (_defaultValue != null) {
        node.writeFieldName("default");
        node.writeTree(_defaultValue);
    }
    if (_schema != null) {
        node.writeFieldName("type");
        _schema.writeJson(node, names, encSpace);
    }

    if (_props != null) {
        _props.writeJson(node);
    }

    if (_aliases != null) {
        node.writeFieldName("aliases");
        node.writeStartArray();
        for (String name : _aliases) {
            node.writeString(name);
        }
        node.writeEndArray();
    }

    node.writeEndObject();
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:38,代码来源:Field.java

示例8: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Device device, JsonGenerator jGen,
                      SerializerProvider serializer) throws IOException,
        JsonProcessingException {
    jGen.writeStartObject();
    
    jGen.writeStringField("entityClass", device.getEntityClass().getName());
    
    jGen.writeArrayFieldStart("mac");
    jGen.writeString(HexString.toHexString(device.getMACAddress(), 6));
    jGen.writeEndArray();

    jGen.writeArrayFieldStart("ipv4");
    for (Integer ip : device.getIPv4Addresses())
        jGen.writeString(IPv4.fromIPv4Address(ip));
    jGen.writeEndArray();

    jGen.writeArrayFieldStart("vlan");
    for (Short vlan : device.getVlanId())
        if (vlan >= 0)
            jGen.writeNumber(vlan);
    jGen.writeEndArray();
    jGen.writeArrayFieldStart("attachmentPoint");
    for (SwitchPort ap : device.getAttachmentPoints(true)) {
        serializer.defaultSerializeValue(ap, jGen);
    }
    jGen.writeEndArray();

    jGen.writeNumberField("lastSeen", device.getLastSeen().getTime());
    
    jGen.writeEndObject();
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:33,代码来源:DeviceSerializer.java

示例9: createAggregatedResponse

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public static Response createAggregatedResponse(final BasicStatusHolder status, final String performedOn) {
    StreamingOutput streamingOutput = new StreamingOutput() {
        @Override
        public void write(OutputStream outputStream) throws IOException, WebApplicationException {
            JsonGenerator jsonGenerator = JacksonFactory.createJsonGenerator(outputStream);
            jsonGenerator.writeStartObject();
            if (status.hasErrors()) {
                jsonGenerator.writeArrayFieldStart("errors");
                for (StatusEntry error : status.getErrors()) {
                    jsonGenerator.writeStartObject();
                    jsonGenerator.writeNumberField("status", error.getStatusCode());
                    jsonGenerator.writeStringField("message", error.getMessage());
                    jsonGenerator.writeEndObject();
                }
                jsonGenerator.writeEndArray();
            } else {
                String msg = "Pushing " + performedOn + " to Bintray finished" + (status.hasWarnings() ?
                        " with warnings, view the log for details" : " to Bintray finished successfully.");
                jsonGenerator.writeStringField("message", msg);
            }
            jsonGenerator.writeEndObject();
            jsonGenerator.close();
        }
    };
    int statusCode = HttpStatus.SC_OK;
    if (status.hasErrors()) {
        statusCode = status.getErrors().size() > 1 ? HttpStatus.SC_CONFLICT : status.getStatusCode();
    }
    return Response.status(statusCode).entity(streamingOutput).type(MediaType.APPLICATION_JSON_TYPE).build();
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:31,代码来源:BintrayRestHelper.java

示例10: writeJsonFields

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Default implementation for writing schema properties in JSON format
 *
 * @param gen      JSON generator
 * @param names    list of named schemas already written
 * @param encSpace enclosing namespace of the schema
 */
protected void writeJsonFields(JsonGenerator gen, SchemaNames names, String encSpace) throws IOException {
    super.writeJsonFields(gen, names, encSpace);
    gen.writeFieldName("symbols");
    gen.writeStartArray();
    for (String s : _symbols) {
        gen.writeString(s);
    }
    gen.writeEndArray();
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:17,代码来源:EnumSchema.java

示例11: writeJsonFields

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names) throws IOException {
    super.writeJsonFields(gen, names);
    gen.writeFieldName("symbols");
    gen.writeStartArray();
    for (String symbol : symbols) {
        gen.writeString(symbol);
    }
    gen.writeEndArray();
}
 
开发者ID:adohe,项目名称:Bottlenose,代码行数:11,代码来源:EnumSchema.java

示例12: writeJson

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Writes union schema in JSON format
 *
 * @param writer
 * @param names    list of named schemas already written
 * @param encSpace enclosing namespace of the schema
 */
protected void writeJson(JsonGenerator writer, SchemaNames names,
                         String encSpace)
        throws IOException {
    writer.writeStartArray();
    for (Schema schema : _schemas) {
        schema.writeJson(writer, names, encSpace);
    }
    writer.writeEndArray();
}
 
开发者ID:archcentric,项目名称:BaijiSerializer4J,代码行数:17,代码来源:UnionSchema.java

示例13: writeValues

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private void writeValues(final CollectionPage<Object> value, final JsonGenerator jgen) throws IOException {
    jgen.writeArrayFieldStart("values");
    for (final Object obj : value) {
        jgen.writeObject(obj);
    }
    jgen.writeEndArray();
}
 
开发者ID:JohnDeere,项目名称:MyJohnDeereAPI-OAuth-Java-Client,代码行数:8,代码来源:CollectionPageSerializer.java

示例14: writeJSON

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void writeJSON(JsonGenerator gen, SchemaNames names) throws IOException {
    gen.writeStartArray();
    for (Schema schema : schemas) {
        schema.writeJSON(gen, names);
    }
    gen.writeEndArray();
}
 
开发者ID:adohe,项目名称:Bottlenose,代码行数:9,代码来源:UnionSchema.java

示例15: writeJSON

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Write field in JSON Format.
 */
protected void writeJSON(JsonGenerator writer, SchemaNames names) throws IOException {
    writer.writeStartObject();
    JsonHelper.writeIfNotNullOrEmpty(writer, "name", name);
    JsonHelper.writeIfNotNullOrEmpty(writer, "doc", doc);

    if (defaultValue != null) {
        writer.writeFieldName("default");
        writer.writeTree(defaultValue);
    }

    if (ordering != null) {
        writer.writeStringField("order", ordering.name);
    }

    writer.writeFieldName("type");
    schema.writeJSON(writer, names);

    if (props != null) {
        props.writeJSON(writer);
    }

    if (aliases != null && aliases.size() > 0) {
        writer.writeFieldName("aliases");
        writer.writeStartArray();
        for (String alias : aliases) {
            writer.writeString(alias);
        }
        writer.writeEndArray();
    }
    writer.writeEndObject();
}
 
开发者ID:adohe,项目名称:Bottlenose,代码行数:35,代码来源:Field.java


注:本文中的org.codehaus.jackson.JsonGenerator.writeEndArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。