io.camunda.exporter.SchemaResourceSerializer Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.exporter;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
public final class SchemaResourceSerializer {
private static final ObjectMapper MAPPER = new ObjectMapper();
private SchemaResourceSerializer() {}
public static Map serialize(
final Function jacksonGenerator,
final Consumer serialize)
throws IOException {
try (final var out = new StringWriter();
final var jsonGenerator = new JsonFactory().createGenerator(out);
final jakarta.json.stream.JsonGenerator jacksonJsonpGenerator =
jacksonGenerator.apply(jsonGenerator)) {
serialize.accept(jacksonJsonpGenerator);
jacksonJsonpGenerator.flush();
return MAPPER.readValue(out.toString(), new TypeReference<>() {});
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy