All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.model.support.AbstractTemplateSynchronisationSource Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.support;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.nemerosa.ontrack.json.ObjectMapperFactory;
import net.nemerosa.ontrack.model.exceptions.TemplateSynchronisationSourceConfigParseException;
import net.nemerosa.ontrack.model.structure.TemplateSynchronisationSource;

public abstract class AbstractTemplateSynchronisationSource implements TemplateSynchronisationSource {

    protected final ObjectMapper objectMapper = ObjectMapperFactory.create();
    private final Class configType;

    protected AbstractTemplateSynchronisationSource(Class configType) {
        this.configType = configType;
    }

    @Override
    public T parseConfig(JsonNode node) {
        try {
            return objectMapper.treeToValue(node, configType);
        } catch (JsonProcessingException e) {
            throw new TemplateSynchronisationSourceConfigParseException(e);
        }
    }

    @Override
    public JsonNode forStorage(T config) {
        return objectMapper.valueToTree(config);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy