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

ai.libs.hasco.gui.statsplugin.ComponentInstanceSerializer Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 0.2.1
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy