本文整理匯總了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;
}