本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.writerWithDefaultPrettyPrinter方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.writerWithDefaultPrettyPrinter方法的具体用法?Java ObjectMapper.writerWithDefaultPrettyPrinter怎么用?Java ObjectMapper.writerWithDefaultPrettyPrinter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.writerWithDefaultPrettyPrinter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void write(SecurityAnalysisResult result, Writer writer) throws IOException {
Objects.requireNonNull(result);
Objects.requireNonNull(writer);
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(SecurityAnalysisResult.class, new SecurityAnalysisResultSerializer());
module.addSerializer(NetworkMetadata.class, new NetworkMetadataSerializer());
module.addSerializer(PostContingencyResult.class, new PostContingencyResultSerializer());
module.addSerializer(LimitViolationsResult.class, new LimitViolationsResultSerializer());
module.addSerializer(LimitViolation.class, new LimitViolationSerializer());
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
objectMapper.registerModule(module);
ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
objectWriter.writeValue(writer, result);
}
示例2: write
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static void write(Contingency object, Path jsonFile) {
Objects.requireNonNull(object);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
mapper.registerModule(module);
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, object);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: exportStatus
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public boolean exportStatus(String outputFile) {
Repository frozenRepository = this.repository.getSnapshotTo(this.repository.getRoot());
File dumpFile = new File(outputFile);
try(FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw)) {
JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
ObjectNode mainNode = jsonFactory.objectNode();
for (ByteArrayWrapper address : frozenRepository.getAccountsKeys()) {
if(!address.equals(new ByteArrayWrapper(ZERO_BYTE_ARRAY))) {
mainNode.set(Hex.toHexString(address.getData()), createAccountNode(mainNode, address.getData(), frozenRepository));
}
}
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
bw.write(writer.writeValueAsString(mainNode));
return true;
} catch (IOException e) {
logger.error(e.getMessage(), e);
panicProcessor.panic("dumpstate", e.getMessage());
return false;
}
}
示例4: compareJson
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void compareJson(String expected, String actual) throws IOException {
if(ElasticsearchCluster.USE_EXTERNAL_ES5){
// ignore json comparison for now
return;
}
ObjectMapper m = new ObjectMapper();
JsonNode expectedRootNode = m.readTree(expected);
JsonNode actualRootNode = m.readTree(actual);
if (!expectedRootNode.equals(actualRootNode)) {
ObjectWriter writer = m.writerWithDefaultPrettyPrinter();
String message = String.format("Comparison between JSON values failed.\nExpected:\n%s\nActual:\n%s", expected, actual);
// assertEquals gives a better diff
assertEquals(message, writer.writeValueAsString(expectedRootNode), writer.writeValueAsString(actualRootNode));
throw new RuntimeException(message);
}
}
示例5: write
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void write(LoadFlowResult result, Path jsonFile) {
Objects.requireNonNull(result);
Objects.requireNonNull(jsonFile);
try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(LoadFlowResult.class, new LoadFlowResultSerializer());
objectMapper.registerModule(module);
ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, result);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例6: Json
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private Json(ObjectMapper mapper) {
this.mapper = mapper;
this.writer = mapper.writer();
this.prettyWriter = mapper.writerWithDefaultPrettyPrinter();
}
示例7: createObjectWriter
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static ObjectWriter createObjectWriter(ObjectMapper objectMapper, boolean prettyPrintEnabled) {
ObjectWriter objectWriter = prettyPrintEnabled
? objectMapper.writerWithDefaultPrettyPrinter()
: objectMapper.writer();
return objectWriter.withoutFeatures(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
}