Java Code Examples for org.codehaus.jackson.map.ObjectMapper#getJsonFactory()

The following examples show how to use org.codehaus.jackson.map.ObjectMapper#getJsonFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonObjectMapperWriter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example 2
Source File: StatePool.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: JsonObjectMapperWriter.java    From big-c with Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example 4
Source File: StatePool.java    From big-c with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 5
Source File: TaggerServiceImpl.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
private int getCurrentRetrainingThreshold() throws Exception {
	try {
		String retrainingThreshold = this.getRetainingThreshold();

		ObjectMapper mapper = JacksonWrapper.getObjectMapper();
		JsonFactory factory = mapper.getJsonFactory(); // since 2.1 use
														// mapper.getFactory()
														// instead
		JsonParser jp = factory.createJsonParser(retrainingThreshold);
		JsonNode actualObj = mapper.readTree(jp);

		JsonNode nameNode = actualObj.get("sampleCountThreshold");

		int sampleCountThreshold = Integer.parseInt(nameNode.asText());

		return sampleCountThreshold;
	} catch (Exception e) {
		logger.error("Exception while getting CurrentRetrainingThreshold", e);
		return 50;

	}
}
 
Example 6
Source File: TestHistograms.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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.");
    }
  }
}
 
Example 7
Source File: TestHistograms.java    From big-c with Apache License 2.0 5 votes vote down vote up
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.");
    }
  }
}
 
Example 8
Source File: TestHistograms.java    From RDFS with Apache License 2.0 5 votes vote down vote up
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.");
    }
  }
}
 
Example 9
Source File: GeoDynamoDBServlet.java    From reinvent2013-mobile-photo-share with Apache License 2.0 5 votes vote down vote up
public void init() throws ServletException {
	geoDataManager = Utilities.getInstance().setupGeoDataManager();
	config = geoDataManager.getGeoDataManagerConfiguration();

	mapper = new ObjectMapper();
	factory = mapper.getJsonFactory();

	Utilities.getInstance().setupTable();
}
 
Example 10
Source File: BackportedObjectReader.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor used by {@link ObjectMapper} for initial instantiation
 */
protected BackportedObjectReader(ObjectMapper mapper, JavaType valueType, Object valueToUpdate) {
    _rootDeserializers = ReflectionUtils.getField(ROOT_DESERIALIZERS, mapper);
    _provider = mapper.getDeserializerProvider();
    _jsonFactory = mapper.getJsonFactory();

    // must make a copy at this point, to prevent further changes from trickling down
    _config = mapper.copyDeserializationConfig();

    _valueType = valueType;
    _valueToUpdate = valueToUpdate;
    if (valueToUpdate != null && valueType.isArrayType()) {
        throw new IllegalArgumentException("Can not update an array value");
    }
}
 
Example 11
Source File: Anonymizer.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 12
Source File: Anonymizer.java    From big-c with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 13
Source File: GeoDynamoDBServlet.java    From dynamodb-geo with Apache License 2.0 4 votes vote down vote up
public void init() throws ServletException {
	setupGeoDataManager();

	mapper = new ObjectMapper();
	factory = mapper.getJsonFactory();
}