本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerator.setPrettyPrinter方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.setPrettyPrinter方法的具体用法?Java JsonGenerator.setPrettyPrinter怎么用?Java JsonGenerator.setPrettyPrinter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.setPrettyPrinter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportTo
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
/**
* Exports data to a {@link Writer}.
*
* @param writer the writer
* @throws NitriteIOException if there is any error while writing the data.
*/
public void exportTo(Writer writer) {
JsonGenerator generator;
try {
generator = jsonFactory.createGenerator(writer);
generator.setPrettyPrinter(new DefaultPrettyPrinter());
} catch (IOException ioe) {
throw new NitriteIOException(EXPORT_WRITER_ERROR, ioe);
}
NitriteJsonExporter jsonExporter = new NitriteJsonExporter(db);
jsonExporter.setGenerator(generator);
jsonExporter.setOptions(options);
try {
jsonExporter.exportData();
} catch (IOException | ClassNotFoundException e) {
throw new NitriteIOException(EXPORT_WRITE_ERROR, e);
}
}
示例2: enableDisableJSONGeneratorFeature
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
private void enableDisableJSONGeneratorFeature(JsonGenerator jg) {
jg.enable(Feature.ESCAPE_NON_ASCII);
jg.disable(Feature.AUTO_CLOSE_TARGET);
jg.setPrettyPrinter(new DefaultPrettyPrinter());
if (PDXTOJJSON_UNQUOTEFIELDNAMES)
jg.disable(Feature.QUOTE_FIELD_NAMES);
}
示例3: startPartition
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void startPartition(WritePartition partition) throws Exception {
// close previous partition if open.
if(this.partition != null){
close();
}
this.partition = partition;
try {
this.fileName = fs.canonicalizePath(partition.qualified(location, prefix + "_0." + extension));
stream = fs.create(fileName);
JsonGenerator generator = factory.createGenerator(stream).useDefaultPrettyPrinter();
if (uglify) {
generator = generator.setPrettyPrinter(new MinimalPrettyPrinter(LINE_FEED));
}
if(useExtendedOutput){
gen = new ExtendedJsonOutput(generator);
}else{
gen = new BasicJsonOutput(generator);
}
logger.debug("Created file: {}", fileName);
} catch (IOException ex) {
throw UserException.dataWriteError(ex)
.message("Failure writing JSON file %s.", fileName)
.build(logger);
}
}
示例4: createGenerator
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException {
JsonGenerator generator = super.createGenerator(out, enc);
generator.setPrettyPrinter(pp);
return generator;
}
示例5: write
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
long write(File file) throws IOException {
long timestamp = System.currentTimeMillis();
if (file.exists()) {
file.delete();
}
JsonFactory f = new JsonFactory();
JsonGenerator g = f.createGenerator(file, JsonEncoding.UTF8);
g.setPrettyPrinter(new DefaultPrettyPrinter() );
g.writeStartObject();
g.writeFieldName("database");
g.writeStartObject();
// Nome database
g.writeStringField("name",databaseName);
// Tabelle
g.writeFieldName("tables");
g.writeStartArray();
for (Map.Entry<String, Integer> entry : tablesToWrite.entrySet()) {
g.writeStartObject();
g.writeStringField("name",entry.getKey());
g.writeArrayFieldStart("records");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
for (int i = 0; i < entry.getValue();++i) {
g.writeStartObject();
g.writeNumberField("cId", new Date().getTime());
String name = entry.getKey();
name = name + " " + i;
g.writeStringField("name", name);
g.writeStringField("dateCreated", simpleDateFormat.format(new Date()));
g.writeStringField("dateUpdated", simpleDateFormat.format(new Date()));
g.writeEndObject();
}
g.writeEndArray();
g.writeEndObject();
}
g.writeEndArray();
g.writeEndObject();
g.writeEndObject();
g.close();
return System.currentTimeMillis() - timestamp;
}