ai.libs.hasco.gui.statsplugin.ComponentInstanceSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hasco Show documentation
Show all versions of hasco Show documentation
HASCO is a framework for reducing configuration tasks (e.g. software system configuration or algorithm configuration) into an HTN planning problem. This can then in turn be reduced to a graph search problem that can be solved by any kind of standard graph search algorithm, e.g., breadth-first-search.
package ai.libs.hasco.gui.statsplugin;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import ai.libs.hasco.model.ComponentInstance;
public class ComponentInstanceSerializer {
private ObjectMapper objectMapper;
public ComponentInstanceSerializer() {
initializeObjectMapper();
}
public String serializeComponentInstance(ComponentInstance componentInstance) throws JsonProcessingException {
return objectMapper.writeValueAsString(componentInstance);
}
public ComponentInstance deserializeComponentInstance(String serializedComponentInstance) throws IOException {
return objectMapper.readValue(serializedComponentInstance, ComponentInstance.class);
}
private void initializeObjectMapper() {
objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
// make sure that the object mapper stores type information when serializing objects
objectMapper.enableDefaultTyping();
}
}