當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectMapper.getJsonFactory方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.map.ObjectMapper.getJsonFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectMapper.getJsonFactory方法的具體用法?Java ObjectMapper.getJsonFactory怎麽用?Java ObjectMapper.getJsonFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.map.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.getJsonFactory方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: JsonObjectMapperWriter

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的package包/類
public JsonObjectMapperWriter(OutputStream output, boolean prettyPrint) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(
      SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);

  // define a module
  SimpleModule module = new SimpleModule("Default Serializer",  
                                         new Version(0, 1, 1, "FINAL"));
  // add various serializers to the module
  //   add default (all-pass) serializer for all rumen specific data types
  module.addSerializer(DataType.class, new DefaultRumenSerializer());
  //   add a serializer to use object.toString() while serializing
  module.addSerializer(ID.class, new ObjectStringSerializer<ID>());
  
  // register the module with the object-mapper
  mapper.registerModule(module);

  mapper.getJsonFactory();
  writer = mapper.getJsonFactory().createJsonGenerator(
      output, JsonEncoding.UTF8);
  if (prettyPrint) {
    writer.useDefaultPrettyPrinter();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:JsonObjectMapperWriter.java

示例2: write

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的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

示例3: main

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的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

示例4: initialize

import org.codehaus.jackson.map.ObjectMapper; //導入方法依賴的package包/類
private void initialize(String[] args) throws Exception {
  try {
    for (int i = 0; i < args.length; ++i) {
      if ("-trace".equals(args[i])) {
        anonymizeTrace = true;
        inputTracePath = new Path(args[i+1]);
        outputTracePath = new Path(args[i+2]);
        i +=2;
      }
      if ("-topology".equals(args[i])) {
        anonymizeTopology = true;
        inputTopologyPath = new Path(args[i+1]);
        outputTopologyPath = new Path(args[i+2]);
        i +=2;
      }
    }
  } catch (Exception e) {
    throw new IllegalArgumentException("Illegal arguments list!", e);
  }
  
  if (!anonymizeTopology && !anonymizeTrace) {
    throw new IllegalArgumentException("Invalid arguments list!");
  }
  
  statePool = new StatePool();
  // initialize the state manager after the anonymizers are registered
  statePool.initialize(getConf());
   
  outMapper = new ObjectMapper();
  // define a module
  SimpleModule module = new SimpleModule("Anonymization Serializer",  
                                         new Version(0, 1, 1, "FINAL"));
  // add various serializers to the module
  // use the default (as-is) serializer for default data types
  module.addSerializer(DataType.class, new DefaultRumenSerializer());
  // use a blocking serializer for Strings as they can contain sensitive 
  // information
  module.addSerializer(String.class, new BlockingSerializer());
  // use object.toString() for object of type ID
  module.addSerializer(ID.class, new ObjectStringSerializer<ID>());
  // use getAnonymizedValue() for data types that have the anonymizing 
  // feature
  module.addSerializer(AnonymizableDataType.class, 
      new DefaultAnonymizingRumenSerializer(statePool, getConf()));
  
  // register the module with the object-mapper
  outMapper.registerModule(module);
  
  outFactory = outMapper.getJsonFactory();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:51,代碼來源:Anonymizer.java


注:本文中的org.codehaus.jackson.map.ObjectMapper.getJsonFactory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。