Java Code Examples for com.fasterxml.jackson.dataformat.yaml.YAMLMapper#writeValueAsString()

The following examples show how to use com.fasterxml.jackson.dataformat.yaml.YAMLMapper#writeValueAsString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtils.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
public static String changeDeploymentNamespaceUpgrade(File deploymentFile, String namespace) {
    YAMLMapper mapper = new YAMLMapper();
    try {
        JsonNode node = mapper.readTree(deploymentFile);
        // Change the docker org of the images in the 050-deployment.yaml
        ObjectNode containerNode = (ObjectNode) node.at("/spec/template/spec/containers").get(0);
        for (JsonNode envVar : containerNode.get("env")) {
            String varName = envVar.get("name").textValue();
            if (varName.matches("STRIMZI_NAMESPACE")) {
                // Replace all the default images with ones from the $DOCKER_ORG org and with the $DOCKER_TAG tag
                ((ObjectNode) envVar).remove("valueFrom");
                ((ObjectNode) envVar).put("value", namespace);
            }
            if (varName.matches("STRIMZI_LOG_LEVEL")) {
                ((ObjectNode) envVar).put("value", "DEBUG");
            }
        }
        return mapper.writeValueAsString(node);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: Kafka.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: KafkaRebalance.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: KafkaBridge.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: KafkaMirrorMaker2.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: KafkaConnect.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
Source File: KafkaTopic.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: KafkaMirrorMaker.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: KafkaConnectS2I.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper().disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: KafkaSpec.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
Source File: KafkaUser.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    YAMLMapper mapper = new YAMLMapper();
    try {
        return mapper.writeValueAsString(this);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: TestUtils.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the {@code subject} of the RoleBinding in the given YAML resource to be the
 * {@code strimzi-cluster-operator} {@code ServiceAccount} in the given namespace.
 * @param roleBindingFile
 * @param namespace
 * @return role
 */
public static String changeRoleBindingSubject(File roleBindingFile, String namespace) {
    YAMLMapper mapper = new YAMLMapper();
    try {
        JsonNode node = mapper.readTree(roleBindingFile);
        ArrayNode subjects = (ArrayNode) node.get("subjects");
        ObjectNode subject = (ObjectNode) subjects.get(0);
        subject.put("kind", "ServiceAccount")
                .put("name", "strimzi-cluster-operator")
                .put("namespace", namespace);
        return mapper.writeValueAsString(node);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source File: CommonUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Converts JSON to YAML.
 *
 * @param json json representation
 * @return json file as a yaml document
 * @throws IOException If an error occurs while converting JSON to YAML
 */
public static String jsonToYaml(String json) throws IOException {

    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory()
            .enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
    JsonNode jsonNodeTree = yamlReader.readTree(json);
    YAMLMapper yamlMapper = new YAMLMapper()
            .disable(YAMLGenerator.Feature.SPLIT_LINES)
            .enable(YAMLGenerator.Feature.INDENT_ARRAYS)
            .disable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
            .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
            .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
            .enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS);
    return yamlMapper.writeValueAsString(jsonNodeTree);
}