package design.persistence.importexport; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.json.JsonMapper; import java.io.File; import java.io.IOException; public class JSONHandler implements DataHandler { private final DataSource dataSource; private final JsonMapper jsonMapper = new JsonMapper(); public JSONHandler(DataSource dataSource) { this.dataSource = dataSource; } @Override public void importData(File file) throws IOException { JsonNode tree = jsonMapper.readTree(file); dataSource.importData(tree); } @Override public void exportData(File file) throws IOException{ JsonNode tree = dataSource.exportData(); jsonMapper.writerWithDefaultPrettyPrinter().writeValue(file, tree); } }