當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。