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


Java JsonGenerator.writeObject方法代码示例

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


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

示例1: write

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private void write(DataOutput out) throws IOException {
  // This is just a JSON experiment
  System.out.println("Dumping the StatePool's in JSON format.");
  ObjectMapper outMapper = new ObjectMapper();
  outMapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
  // define a module
  SimpleModule module = new SimpleModule("State Serializer",  
      new Version(0, 1, 1, "FINAL"));
  // add the state serializer
  //module.addSerializer(State.class, new StateSerializer());

  // register the module with the object-mapper
  outMapper.registerModule(module);

  JsonFactory outFactory = outMapper.getJsonFactory();
  JsonGenerator jGen = 
    outFactory.createJsonGenerator((DataOutputStream)out, JsonEncoding.UTF8);
  jGen.useDefaultPrettyPrinter();

  jGen.writeObject(this);
  jGen.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:StatePool.java

示例2: main

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
  final Configuration conf = new Configuration();
  final FileSystem lfs = FileSystem.getLocal(conf);

  for (String arg : args) {
    Path filePath = new Path(arg).makeQualified(lfs);
    String fileName = filePath.getName();
    if (fileName.startsWith("input")) {
      LoggedDiscreteCDF newResult = histogramFileToCDF(filePath, lfs);
      String testName = fileName.substring("input".length());
      Path goldFilePath = new Path(filePath.getParent(), "gold"+testName);

      ObjectMapper mapper = new ObjectMapper();
      JsonFactory factory = mapper.getJsonFactory();
      FSDataOutputStream ostream = lfs.create(goldFilePath, true);
      JsonGenerator gen = factory.createJsonGenerator(ostream,
          JsonEncoding.UTF8);
      gen.useDefaultPrettyPrinter();
      
      gen.writeObject(newResult);
      
      gen.close();
    } else {
      System.err.println("Input file not started with \"input\". File "+fileName+" skipped.");
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestHistograms.java

示例3: writeSuccessfulDeploymentResponse

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Writes the spec implementation response
 *
 * @param repoService Instance of repo service
 * @param response    Response object
 * @param repoPath    Repo path of deployed artifact
 * @param url         Final reachable URI of deployed file
 */
public void writeSuccessfulDeploymentResponse(InternalRepositoryService repoService, ArtifactoryResponse response,
        RepoPath repoPath, String url, boolean isDirectory) throws IOException {

    Writer writer = response.getWriter();
    response.setHeader(HttpHeaders.LOCATION, url);
    response.setStatus(HttpStatus.SC_CREATED);
    response.setContentType(ArtifactRestConstants.MT_ITEM_CREATED);
    RestBaseStorageInfo storageInfo;
    if (isDirectory) {
        storageInfo = getFolderInfo(repoService, repoPath, url);
    } else {
        storageInfo = getFileInfo(repoService, repoPath, url);
    }

    JsonGenerator jsonGenerator = JacksonFactory.createJsonGenerator(writer);
    jsonGenerator.writeObject(storageInfo);
    jsonGenerator.close();
    writer.flush();
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:28,代码来源:SuccessfulDeploymentResponseHelper.java

示例4: anonymizeTrace

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private void anonymizeTrace() throws Exception {
  if (anonymizeTrace) {
    System.out.println("Anonymizing trace file: " + inputTracePath);
    JobTraceReader reader = null;
    JsonGenerator outGen = null;
    Configuration conf = getConf();
    
    try {
      // create a generator
      outGen = createJsonGenerator(conf, outputTracePath);

      // define the input trace reader
      reader = new JobTraceReader(inputTracePath, conf);
      
      // read the plain unanonymized logged job
      LoggedJob job = reader.getNext();
      
      while (job != null) {
        // write it via an anonymizing channel
        outGen.writeObject(job);
        // read the next job
        job = reader.getNext();
      }
      
      System.out.println("Anonymized trace file: " + outputTracePath);
    } finally {
      if (outGen != null) {
        outGen.close();
      }
      if (reader != null) {
        reader.close();
      }
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:36,代码来源:Anonymizer.java

示例5: anonymizeTopology

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private void anonymizeTopology() throws Exception {
  if (anonymizeTopology) {
    System.out.println("Anonymizing topology file: " + inputTopologyPath);
    ClusterTopologyReader reader = null;
    JsonGenerator outGen = null;
    Configuration conf = getConf();

    try {
      // create a generator
      outGen = createJsonGenerator(conf, outputTopologyPath);

      // define the input cluster topology reader
      reader = new ClusterTopologyReader(inputTopologyPath, conf);
      
      // read the plain unanonymized logged job
      LoggedNetworkTopology job = reader.get();
      
      // write it via an anonymizing channel
      outGen.writeObject(job);
      
      System.out.println("Anonymized topology file: " + outputTopologyPath);
    } finally {
      if (outGen != null) {
        outGen.close();
      }
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:Anonymizer.java

示例6: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public void serialize(AnonymizableDataType object, JsonGenerator jGen, 
                      SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object val = object.getAnonymizedValue(statePool, conf);
  // output the data if its a string
  if (val instanceof String) {
    jGen.writeString(val.toString());
  } else {
    // let the mapper (JSON generator) handle this anonymized object.
    jGen.writeObject(val);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:DefaultAnonymizingRumenSerializer.java

示例7: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public void serialize(DataType object, JsonGenerator jGen, SerializerProvider sProvider) 
throws IOException, JsonProcessingException {
  Object data = object.getValue();
  if (data instanceof String) {
    jGen.writeString(data.toString());
  } else {
    jGen.writeObject(data);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:10,代码来源:DefaultRumenSerializer.java

示例8: jsParam

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public static String jsParam(Object parameter) {
    Writer writer = new StringWriter();
    try {
        JsonGenerator generator = JacksonFactory.createJsonGenerator(writer);
        generator.writeObject(parameter);
        return writer.toString();
    } catch (IOException e) {
        throw new RuntimeException("Could not write js param '" + parameter + "'.", e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:13,代码来源:JavaScriptUtils.java

示例9: generateEntry

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void generateEntry(JsonGenerator generator,
        Map.Entry<String, Object> x) throws IOException,
        JsonGenerationException, JsonProcessingException {
    if (x.getValue() == null) {
        if (!filterOutNullValue) {
            generator.writeFieldName(x.getKey());
            generator.writeNull();
        }
        return;
    }

    generator.writeFieldName(x.getKey());
    if (Map.class.isAssignableFrom(x.getValue().getClass())) {
        encodeMap((Map<String, Object>) x.getValue(), generator);
    } else if (x.getValue().getClass().isArray()) {
        generator.writeStartArray();
        int length = Array.getLength(x.getValue());
        for (int i = 0; i < length; i++) {
            generator.writeObject(Array.get(x.getValue(), i));    
        }
        generator.writeEndArray();
    } else if (x.getValue() instanceof Collection) {
        generator.writeStartArray();
        Iterator iterator = ((Collection) (x.getValue())).iterator();
        while (iterator.hasNext()) {
            generator.writeObject(iterator.next());    
        }
        generator.writeEndArray();
    } else {
        generator.writeObject(x.getValue());
    }
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:34,代码来源:JSONMessageSerializer.java

示例10: jsonProperties

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private String jsonProperties(RepoPath repoPath, Properties properties) throws IOException {
    ItemProperties itemProperties = new ItemProperties();
    for (String propertyName : properties.keySet()) {
        Set<String> propertySet = properties.get(propertyName);
        if ((propertySet != null) && !propertySet.isEmpty()) {
            itemProperties.properties.put(propertyName, Iterables.toArray(propertySet, String.class));
        }
    }
    itemProperties.slf = repoPath.getRepoKey() + "/" + repoPath.getPath();
    StringWriter out = new StringWriter();
    JsonGenerator generator = JacksonFactory.createJsonGenerator(out);
    generator.writeObject(itemProperties);
    return out.getBuffer().toString();
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:15,代码来源:DownloadServiceImpl.java

示例11: JsonBlobWrapper

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
JsonBlobWrapper(final Object jsonObject) {
    // TODO: Make sure the Global Artifactory executor is used
    super(new OutputToInputStream() {
        @Override
        protected void write(OutputStream outputStream) throws IOException {
            JsonGenerator jsonGenerator = JacksonFactory.createJsonGenerator(outputStream);
            jsonGenerator.writeObject(jsonObject);
        }
    });
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:11,代码来源:JsonBlobWrapper.java

示例12: 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

示例13: generateFromObject

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
 * Generate a simple object and make sure it has no null fields
 */
public void generateFromObject() throws IOException {
    Build build = new Build();
    StringWriter out = new StringWriter();
    JsonGenerator generator = JacksonFactory.createJsonGenerator(out);
    generator.writeObject(build);
    String result = out.getBuffer().toString();

    System.out.println("result = " + result);

    Assert.assertFalse(result.contains("null"), "Result should not contain null fields");
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:15,代码来源:BuildInfoIOTest.java

示例14: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Boolean bool, JsonGenerator jsonGenerator,
		SerializerProvider serializerProvider) throws IOException,
		JsonProcessingException {
	if (bool != null)
		jsonGenerator.writeObject(bool ? 1 : 0);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:8,代码来源:BooleanToIntegerSerializer.java

示例15: serialize

import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(CloudResources value, JsonGenerator jgen, SerializerProvider provider) throws
        IOException, JsonProcessingException {
    jgen.writeObject(value.asList());
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:6,代码来源:CloudResources.java


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