static void serialize()

in tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java [182:213]


    static void serialize(final Path catalogPath, ArtifactModel<?> model) {
        final Path out = catalogPath.resolve(model.getKind() + "s")
                .resolve(model.getName() + ".json");
        try {
            Files.createDirectories(out.getParent());
        } catch (IOException e) {
            throw new RuntimeException("Could not create " + out.getParent(), e);
        }
        String rawJson;
        switch (Kind.valueOf(model.getKind())) {
        case component:
            rawJson = JsonMapper.createParameterJsonSchema((ComponentModel) model);
            break;
        case language:
            rawJson = JsonMapper.createParameterJsonSchema((LanguageModel) model);
            break;
        case dataformat:
            rawJson = JsonMapper.createParameterJsonSchema((DataFormatModel) model);
            break;
        case other:
            rawJson = JsonMapper.createJsonSchema((OtherModel) model);
            break;
        default:
            throw new IllegalStateException("Cannot serialize kind " + model.getKind());
        }

        try {
            Files.write(out, rawJson.getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            throw new RuntimeException("Could not write to " + out, e);
        }
    }