当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.writerWithDefaultPrettyPrinter方法代码示例

本文整理汇总了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);

}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:19,代码来源:SecurityAnalysisResultSerializer.java

示例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);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:ContingencyJsonTest.java

示例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;
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:24,代码来源:NetworkStateExporter.java

示例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);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:ElasticBaseTestQuery.java

示例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);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:16,代码来源:LoadFlowResultSerializer.java

示例6: Json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private Json(ObjectMapper mapper) {
    this.mapper = mapper;
    this.writer = mapper.writer();
    this.prettyWriter = mapper.writerWithDefaultPrettyPrinter();
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:6,代码来源:Json.java

示例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);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:7,代码来源:TemplateRenderer.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.writerWithDefaultPrettyPrinter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。