當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。